Select example(s) of templated node class that can be used in a linked list.
MathWorks technical mcq question, verified with a worked answer. Free to practise - no sign-up.
Select example(s) of templated node class that can be used in a linked list.
Pick ONE option
1. template
class node { node* next; T value; } 2. template
class node { public: node* next; T value; } 3. class class node { node* next; T value; }
4. class class node { public: node* next; T value; }
Show answer & explanation
Option B is the correct syntax for a templated node class in C++. The template keyword must precede the class declaration, and the members should be declared as public to be accessible in a linked list implementation. Options C and D use invalid syntax (class instead of template
Step-by-step Derivation:
In C++, templated classes follow the syntax: template