I am trying to create a node class to be used in a weighted graph. definition is below, I tried to be as specific as possible, but please let me know if you have any questions
end goal: I want to be able to make an adjacency list like so.
"TUCSON" : ("PHOENIX" , 5), "LA" : ("TUC" , 15).
or
0: (1, 5), 2: (0, 15);
note how source, dest have the same type, while cost is always numeric.
When I run the below code, I get the following errors: from main.cpp: "No matching constructor for initialization of 'Node<int, int>'"
these are the build time errors I am getting (replaced the gilepath with [path] for readability)
Semantic Issue Group
[path]List.h:23:5: Constructor for 'Node<int, int>' must explicitly initialize the reference member 'data'
[path]main.cpp:4:10: In file included from [path]main.cpp:4:
[path]main.cpp:9:19: In instantiation of member function 'Node<int, int>::Node' requested here
[path]List.h:20:19: Declared here
[path]List.h:47:20: Assigning to 'int' from incompatible type 'int *'; dereference with *
[path]main.cpp:4:10: In file included from [path]main.cpp:4:
[path]List.h:49:16: No viable overloaded '='
[path]main.cpp:4:10: In file included from [path]main.cpp:4:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:512:11: Candidate function not viable: no known conversion from 'pair<int, int> *' to 'const typename conditional<is_copy_assignable<first_type>::value && is_copy_assignable<second_type>::value, pair<int, int>, __nat>::type' (aka 'const std::__1::pair<int, int>') for 1st argument; dereference the argument with *
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:525:11: Candidate function not viable: no known conversion from 'pair<int, int> *' to 'typename conditional<is_move_assignable<first_type>::value && is_move_assignable<second_type>::value, pair<int, int>, __nat>::type' (aka 'std::__1::pair<int, int>') for 1st argument; dereference the argument with *
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/utility:334:62: Candidate template ignored: disabled by 'enable_if' [with _Tuple = std::__1::pair<int, int> *]
template <typename T0, typename T1>
class Node{
public:
T0 source; //type could be an int specifying the numerical index of source
//or a string, specifying the alphanumerical name of source.
pair<T0, T1> &data; //data has the form (dest, cost), where source and dest are of same type (ie both or int or both string)
//cost is always a int or float;
Node<T0, T1>* next = nullptr;
Node(T0 src, pair<T0,T1>& data); //paramerized c-tor
Node();
~Node();
Node(const Node<T0, T1>& orig_Node); //copy c-tor
};
template <typename T0, typename T1>
//default constructor
Node<T0, T1>::Node(){
source = 0;
data = {0,0};
}
template <typename T0, typename T1>
Node<T0, T1>::Node(const Node<T0, T1>& orig_Node){
T0 source_copy = new T0();
*source_copy = orig_Node.source;
pair<T0,T1>* data_copy = new pair<T0, T1>();
*data_copy = *(orig_Node.data);
Node<T0, T1>*next = orig_Node.next;
}
template <typename T0, typename T1>
Node<T0, T1>::Node(T0 src, pair<T0,T1>& input_data){
source = new T0();
source = src;
data = new pair<T0,T1>();
this->data = input_data;
}
int main(int argc, const char * argv[]) {
Node<int,int> n0(0, {1,3});
cout << "n0: " << "(" << n0.data.first << "," << n0.data.second << ")" << endl;
int a[5] = {1,2,3,4};
return 0;
};