returning pointer to a struct defined inside a class

This is a discussion on returning pointer to a struct defined inside a class within the C++ Programming forums, part of the General Programming Boards category; I have a problem with doing this Code: .h file class c1{ private: struct node{ int value; }; struct node ...

  1. #1
    nik
    nik is offline
    Registered User
    Join Date
    Nov 2010
    Posts
    44

    returning pointer to a struct defined inside a class

    I have a problem with doing this

    Code:
    .h file
    
    class c1{
    
      private:
    
         struct node{
                   int value;
          };
    
      struct node *getvalue();
    
      public:
    
           ...
    
    };
    Code:
    .cpp file
    
    struct node* c1::getvalue(){ ...}
    it doesnt let me do this.. can someone please explain me why?

    thanks in advance

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,630
    Since node is a nested class of c1, it should be:
    Code:
    c1::node* c1::getvalue(){ ...}
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    nik
    nik is offline
    Registered User
    Join Date
    Nov 2010
    Posts
    44
    Quote Originally Posted by laserlight View Post
    Since node is a nested class of c1, it should be:
    Code:
    c1::node* c1::getvalue(){ ...}
    thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Referencing pointer inside a structure pointer
    By SasDutta in forum C Programming
    Replies: 2
    Last Post: 11-11-2010, 10:33 AM
  2. Example of Struct inside Class.
    By floatingdots in forum C++ Programming
    Replies: 6
    Last Post: 09-17-2010, 06:44 AM
  3. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 03:25 AM
  4. Returning a pointer to a struct array
    By osiris^ in forum C Programming
    Replies: 14
    Last Post: 09-13-2009, 10:21 AM
  5. returning a pointer of a struct of a struct array...
    By myrddinb in forum C Programming
    Replies: 1
    Last Post: 04-13-2004, 06:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21