Thread: Returning pointer to a nested class

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    2

    Returning pointer to a nested class

    I'm trying to compile this simple code in g++ 4.0.1:
    Code:
    #include <cstdlib>
    
    template <class Data> class MyClass
    {
      public:
    
      private:
    
        class Inside {};
    
        Inside* __func(int x);
    };
    
    template <class Data> Inside* MyClass<Data>::__func(int x) // This is line 14
    { return NULL; }
    And I get :
    test1.cpp:14: error: expected constructor, destructor, or type conversion before ‘*’ token

    I've tried to fix it to no avail, could anyone please explain to me what am I doing wrong ?
    Many thanks in advance,
    stingerkiss

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You have to qualify Inside with MyClass<Data>:: just like you do with __func.

    BTW, identifiers with double underscores are reserved for the implementation, so you shouldn't really be using them in your own code.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    template <class Data>
    typename MyClass<Data>::Inside* MyClass<Data>::__func(int x)
    { return NULL; }
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Aug 2006
    Posts
    2
    Wow! thanks to the fast response! It worked!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer to a class inside the WindowsProcedure function
    By like_no_other in forum Windows Programming
    Replies: 3
    Last Post: 06-01-2009, 12:52 PM
  2. Base-class pointer, accessing object from derived class
    By Korhedron in forum C++ Programming
    Replies: 15
    Last Post: 09-28-2008, 05:30 AM
  3. pointer of array of class
    By 11moshiko11 in forum C++ Programming
    Replies: 5
    Last Post: 04-05-2008, 09:58 AM
  4. Problem constructing a class with a nested struc
    By pliang in forum C++ Programming
    Replies: 3
    Last Post: 04-14-2005, 07:43 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM