template compile success in MSVC but failed in g++

时间:2017-11-13 06:29:07

标签: c++ templates delegates

I'm new to c++ template and got compile error like this

In constructor ‘Delegate0Impl<RetType>::Delegate0Impl()’:
.cpp:11:3: error: ‘m_Closure’ was not declared in this scope
   m_Closure = 0;

But the member 'm_Closure' is defined in the base class as line 4, and it's ok in VS2015(MSBuild?). It seeks like the g++ compile class 'Delegate0Impl' before it's base class 'DelegateImpl', I'm curious about why and how to resolve this, thanks a lot.

Here is the whole source code:

template<class T>
class DelegateImpl {
protected:
    int m_Closure;
};

template<class RetType>
class Delegate0Impl : public DelegateImpl<Delegate0Impl<RetType> > {
public:
    Delegate0Impl() {
        m_Closure = 0;
    }
};

0 个答案:

没有答案