If I do this in a header file alone, it works fine:
generic<typename T>
ref class MyGenericClass
{
protected:
T m_someInternalInformation;
public:
MyGenericClass(void)
{
}
};
...but if I alter the .h file to look like this:
generic<typename T>
ref class MyGenericClass
{
protected:
T m_someInternalInformation;
public:
MyGenericClass();
};
...and a .cpp file like this:
#include "MyGenericClass.h"
MyGenericClass::MyGenericClass(void)
{
}
I get a compiler error:
1>MyGenericClass.cpp(4): error C2955: 'MyGenericClass' : use of class generic requires generic argument list
I've tried adding the generic definition about the constructor definition:
#include "MyGenericClass.h"
generic<typename T>
MyGenericClass::MyGenericClass(void)
{
}
...but I get the same error. What am I missing here?
Found the answer:
generic<typename T>
MyGenericClass<T>::MyGenericClass(void)
{
}
Note the <T>
before the ::
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.