Help with templates (newbie)
-
Hi all, Can someone help me fix and understand why this doesn't work. I keep getting an error saying: error C2079: 'Node::data' uses undefined class 'T' with[ T=T] Here is my code;
template class Node { public: Node * link; Node(T x=0, Node* A = NULL): data(x), link(A) {} T data; }; typedef Node nodePtr;
HELP PLEASE...this is driving me crazy?
-
Hi all, Can someone help me fix and understand why this doesn't work. I keep getting an error saying: error C2079: 'Node::data' uses undefined class 'T' with[ T=T] Here is my code;
template class Node { public: Node * link; Node(T x=0, Node* A = NULL): data(x), link(A) {} T data; }; typedef Node nodePtr;
HELP PLEASE...this is driving me crazy?
You need to check the box that says 'do not treat '<'s as HTML tags, then you need to post your question once only, and finally, you might consider using some sort of moniker, rather than posting anonymously. If you fulfill the first of these, so I can read your code, I'd be happy to look at it for you. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
Hi all, Can someone help me fix and understand why this doesn't work. I keep getting an error saying: error C2079: 'Node::data' uses undefined class 'T' with[ T=T] Here is my code;
template class Node { public: Node * link; Node(T x=0, Node* A = NULL): data(x), link(A) {} T data; }; typedef Node nodePtr;
HELP PLEASE...this is driving me crazy?
Actually, maybe I'm wrong, and you've simply not defined your template at all. In that case, you'd get this error, as the class T does not exist. You need to do this: template Node { // etc But what is the typedef for ? Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
Hi all, Can someone help me fix and understand why this doesn't work. I keep getting an error saying: error C2079: 'Node::data' uses undefined class 'T' with[ T=T] Here is my code;
template class Node { public: Node * link; Node(T x=0, Node* A = NULL): data(x), link(A) {} T data; }; typedef Node nodePtr;
HELP PLEASE...this is driving me crazy?
The offending line is:
typedef Node<class T> nodePtr;
This is not legal because you aren't definingT
here. You can't make a typedef without specifying the template parameters (at least not in VC 6, maybe with PTS you can, but that's off-topic) because a template is just something that generates code, it is not a type. You could do this:typedef Node<int>* nodePtr;
--Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER -
You need to check the box that says 'do not treat '<'s as HTML tags, then you need to post your question once only, and finally, you might consider using some sort of moniker, rather than posting anonymously. If you fulfill the first of these, so I can read your code, I'd be happy to look at it for you. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
Sorry about that, I forgot to log in before. Sorry also about the double post. Here is the code.... template class Node { public: T data; Node * link; Node(T x=0, Node* A = NULL): data(x), link(A) {} }; typedef Node* nodePtr; Many thanks in advance
Like Mike said.... typedef's generally suck anyhow, they mean relying on the IDE or a search all to figure out what something actually *is*. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
-
The offending line is:
typedef Node<class T> nodePtr;
This is not legal because you aren't definingT
here. You can't make a typedef without specifying the template parameters (at least not in VC 6, maybe with PTS you can, but that's off-topic) because a template is just something that generates code, it is not a type. You could do this:typedef Node<int>* nodePtr;
--Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIERtypedef templates are not part of C++ standard, but they are planned for the next version. At least Herb Sutter seems to be very enthusiastic about them.
-
The offending line is:
typedef Node<class T> nodePtr;
This is not legal because you aren't definingT
here. You can't make a typedef without specifying the template parameters (at least not in VC 6, maybe with PTS you can, but that's off-topic) because a template is just something that generates code, it is not a type. You could do this:typedef Node<int>* nodePtr;
--Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIERThe following code compiled correctly:
template <typename T>
class Node { public: T data; };typedef template<typename T> Node<T>* pTnode;
pTnode<int> p;Hosam Aly Mahmoud
-
The following code compiled correctly:
template <typename T>
class Node { public: T data; };typedef template<typename T> Node<T>* pTnode;
pTnode<int> p;Hosam Aly Mahmoud
Using what compiler? --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER
-
Using what compiler? --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER
Microsoft Visual C++ 6.0 with SP5. I said it compiled, but I did not run it.
Hosam Aly Mahmoud