typedef funktioniert nicht



  • Hallo Leute,

    Folgendes Beispiel gibt mir einen compile error:

    template<typename T>
    class Foo
    {
    public:
    	typedef typename T::Test Type;
    };
    
    class Bar : public Foo<Bar>
    {
    	struct Test
    	{
    	};
    };
    

    error C2039: 'Test' : is not a member of 'Bar'

    Die Fehlermeldung versteh ich nicht so ganz.
    Test ist doch ein member von Bar, oder nicht?



  • Zu dem Zeitpunkt

    class Bar : public Foo<Bar>
    

    gibt es

    struct Test
        {
        };
    

    noch nicht, aber es wird in Foo gebraucht.

    Keine Ahnung was du machen willst, aber so geht das nicht.



  • template<typename T>
    struct Foo
    {
         // typedef typename T::Test Type; // nein 
         static void bla()
         {
             typedef typename T::Test Type; // ja
         }
    };
    
    struct Bar : public Foo<Bar>
    {	
        struct Test
        {};
    };
    
    int main()
    {
       Bar b;
    }
    

Anmelden zum Antworten