cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Templated Struct and Class
Templated Struct and Class
Oct 19, 2011 at 7:41pm UTC
PorquePine
(2)
I have a struct the represents a node in a linked list that I want to template:
template <class T>
struct ListNode
{
T comp;
ListNode<T> *link;
}
Now I want to have a class to leverage this list, that is templated with the same type as the struct.
template <class T>
class LinkedList
{
....
ListNode<T> *firstElement;
....
}
Will this ensure that the struct and my class share the same type at runtime, or would I need to define the templating in a different manner? Any advice would be very much appreciated.
Oct 19, 2011 at 7:50pm UTC
ModShop
(1149)
Yes, ListNode will receive the same type that is passed to the template parameter of LinkedList.
Topic archived. No new replies allowed.