Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with templates (newbie)

Help with templates (newbie)

Scheduled Pinned Locked Moved C / C++ / MFC
helpwpfquestion
10 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    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?

    C M 3 Replies Last reply
    0
    • A Anonymous

      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?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      J 1 Reply Last reply
      0
      • A Anonymous

        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?

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • A Anonymous

          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?

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          The offending line is: typedef Node<class T> nodePtr; This is not legal because you aren't defining T 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

          N H 2 Replies Last reply
          0
          • C Christian Graus

            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

            J Offline
            J Offline
            Jay Hova
            wrote on last edited by
            #5

            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

            C 1 Reply Last reply
            0
            • J Jay Hova

              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

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • M Michael Dunn

                The offending line is: typedef Node<class T> nodePtr; This is not legal because you aren't defining T 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

                N Offline
                N Offline
                Nemanja Trifunovic
                wrote on last edited by
                #7

                typedef 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.

                1 Reply Last reply
                0
                • M Michael Dunn

                  The offending line is: typedef Node<class T> nodePtr; This is not legal because you aren't defining T 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

                  H Offline
                  H Offline
                  Hosam Aly Mahmoud
                  wrote on last edited by
                  #8

                  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

                  M 1 Reply Last reply
                  0
                  • H 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

                    M Offline
                    M Offline
                    Michael Dunn
                    wrote on last edited by
                    #9

                    Using what compiler? --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER

                    H 1 Reply Last reply
                    0
                    • M Michael Dunn

                      Using what compiler? --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER

                      H Offline
                      H Offline
                      Hosam Aly Mahmoud
                      wrote on last edited by
                      #10

                      Microsoft Visual C++ 6.0 with SP5. I said it compiled, but I did not run it.

                      Hosam Aly Mahmoud

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups