none
Error C2504 base class undefined

    Question

  •  

    Hi everyone and thank you for reading this, though the problem seems simple but unable to find a way to compile successfully

    to make the problem at it's simplest form here is the entire code for a console application (C++ native)

     

     

    #include "stdafx.h"

    template<typename T> class Base; // forward declaring

    class First : Base<First> { };

    template <typename T> class Second: First { };

    template<typename T> class Base: Second<T> { };

     

    int _tmain(int argc, _TCHAR* argv[])
    {
     return 0;
    }

     

    as I see that the forward declaration is not working!! and no matter what sequance I use these classes this error will come for one of these classes.

     

    what I think I am missing is settings in the compiler that I don't know about.

     

    anyone please..

     

    Thanks in advance.

     

     

     

    Sunday, December 02, 2007 3:59 PM

Answers

  • The forward declaration is correct, however, base class must be defined at the place where derived class defined, following code will compile:

     

    Code Block

    template<typename T> class Base; // forward declaring

    class First { 
    friend Base<int>; // OK
    };

    template <typename T> class Second: First { };

    template<typename T> class Base: Second<T> { };

     

    hope it helps

    rico

     

    Thursday, December 06, 2007 11:54 AM

All replies

  • This is a language question that should be asked in the language forum.

    Sunday, December 02, 2007 9:18 PM
  • The forward declaration is correct, however, base class must be defined at the place where derived class defined, following code will compile:

     

    Code Block

    template<typename T> class Base; // forward declaring

    class First { 
    friend Base<int>; // OK
    };

    template <typename T> class Second: First { };

    template<typename T> class Base: Second<T> { };

     

    hope it helps

    rico

     

    Thursday, December 06, 2007 11:54 AM