problem w/ nested templatized classes

This is a discussion on problem w/ nested templatized classes within the C++ Programming forums, part of the General Programming Boards category; its not really a nested templatized class, but a templatized class that has another class inside it. Code: template <class ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    552

    problem w/ nested templatized classes

    its not really a nested templatized class, but a templatized class that has another class inside it.

    Code:
    template <class T>
    class Outer {
      public:
      ...
      class Inner {
        ...
      };
    };
    
    #include "myclass.cpp"
    I defined the methods in "Inner" like this

    template<class T>
    void Outer<T>::Inner::method1(...) {
    ...
    }

    when I compile and link this code, I get an unresolved external error for all the methods in "Inner", but none for "Outer"

    Is there something wrong with my syntax?
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Not that I can see.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Check syntax for this line you posted.

    Code:
    template<class T>
    void Outer<T>::Inner::method1(...) {
    ...
    }
    Try this solultion.

    Code:
    template<class T>
    void Outer<T>::Inner()
    {
       Inner::method1();
    }
    Kuphryn

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by kuphryn

    Try this solultion.

    Code:
    template<class T>
    void Outer<T>::Inner()
    {
       Inner::method1();
    }
    ¿Que?
    What is that supposed to do?

    I think the code he posted looks correct. The problem could be an old compiler or something not in the posted code.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    Actually im using visual studios 6.0 (i always forget to mention that). Guess im just gonna have to rewrite it (not that big of a deal, the class was already written, i just now have to "templatize it")

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    I believe ClownPimp wanted to define a member function of an inner class.

    Is there a specific reason why you want to implement nested classes? I recommend inheritance for simple designs.

    Kuphryn

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    I have to do it this way. Instructor said so.
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  8. #8
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Try to use a different compiler. For example, use a Linux lab and compile the source code using GNU C++.

    Kuphryn

  9. #9
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    tried that, i but got a whole bunch of errors in my other source, and since the problem only surfaces when I try to link, i will have to fix the other errors first (i hate it when code works fine on MSVC but on gcc it theres tons of errors). I guess Ill have to write some sort of skeleton to see if it will link correctly...
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. classes problem
    By wabbz111 in forum C++ Programming
    Replies: 3
    Last Post: 05-13-2009, 05:57 AM
  2. problem with classes and pointers
    By Akkernight in forum C++ Programming
    Replies: 18
    Last Post: 02-21-2009, 06:21 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  5. Problem with character arrays in classes
    By spoketoosoon in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2004, 03:57 AM

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