Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 '*' ... error 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.

like image 873
jAckOdE Avatar asked Sep 16 '26 17:09

jAckOdE


1 Answers

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.

like image 118
Seth Carnegie Avatar answered Sep 18 '26 05:09

Seth Carnegie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!