c++ question on templates: go here: https://github.com/connectp/cplusplus and an
ID: 3712419 • Letter: C
Question
c++ question on templates:
go here: https://github.com/connectp/cplusplus and answer the following question
1.1 In node.h at line 60, the declaration of key_ and value_ are missing. Provide the declarations here. Recall that the type parameters of the template are used for these class members (see description of class template at top of the file).
1.2 Consider each of the following Node object definitions to be used with the template class Node as defined in node.h.
Select all that are syntactically valid.
a. Node * node1;
b. Node<float, float> node2;
c. Node<int, Robot *> node3; // assuming the Robot class definition is linked
d. Node<int> node4;
e. Node<string, string> node5; // assuming string header is linked
f. Node node6;
1.3 There is no setter provided for setting key_ in the Node class. Please provide the definition of set_key() here using k as the input parameter name. Use k as input parameter name.
Explanation / Answer
Answer 1.1
At line 60, insert the following 2 lines
T1 key_;
T2 value_;
--------------------
Answer 1.2
b. Node<float, float> node2;
c. Node<int, Robot *> node3; // assuming the Robot class definition is linked
e. Node<string, string> node5; // assuming string header is linked
only options b, c and e are correct since the Node class need 2 template parameters - one for key and other for value
-------
Answer 1.3
void set_key(T1 k)
{
key_ = k;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.