开发者

Error: missing type specifier - int assumed. C++ does not support default int

I wrote a sample class with template use. it's fairly simple:

template <class T>
class myClass
{
public:

    // construction, destruction
    myClass();
    virtual ~myClass();
    class Object
    {
    public:
        Object() { m_pNext = NULL; m_pPrev = NULL; }
        ~Object() {}

        T        m_Value;

        Object*  m_pNext;
        Object*  m_pPrev;
    };

public:

    // accessor functions
    Object* Beginning();

private:

    Object* m_pBegin;
    Object* m_pEnd;
    INT m_nCount;

};

template <class T> 
inline myClass<T>::Object* myClass<T>::Beginning()
{ return m_pBegin; }


template <class T>
inline myClass<T>::myClass()
{

}

template <class T>
inline myClass<T>::~myClass()
{

}

I use visual studio 2008, and here is the compile error

error C2143: syntax error : missing ';' before '*' ... err开发者_如何学Pythonor C4430: missing type specifier - int assumed. Note: C++ does not support default-int.

the errors are linked to this line:

inline myClass<T>::Object* myClass<T>::Beginning()

Can anyone tell me what was wrong in this code?

Thanks.


You need to change

template <class T> 
inline myClass<T>::Object* myClass<T>::Beginning()
{ return m_pBegin; }

to

template <class T> 
inline typename myClass<T>::Object* myClass<T>::Beginning()
{ return m_pBegin; }

because myClass<T>::Object is a dependent type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜