invalid use of incomplete type

后端 未结 5 1655
北海茫月
北海茫月 2020-11-30 01:43

I\'m trying to use a typedef from a subclass in my project, I\'ve isolated my problem in the example below.

Does anyone know where I\'m going wrong?

         


        
5条回答
  •  悲哀的现实
    2020-11-30 02:22

    Not exactly what you were asking, but you can make action a template member function:

    template
    class A {
        public:
            //Why doesn't it like this?
            template void action(V var) {
                    (static_cast(this))->do_action();
            }
    };
    
    class B : public A {
        public:
            typedef int mytype;
    
            B() {}
    
            void do_action(mytype var) {
                    // Do stuff
            }
    };
    
    int main(int argc, char** argv) {
        B myInstance;
        return 0;
    }
    

提交回复
热议问题