Sign in to follow this  
f001error

Extern pointers wont work on classes dervied from templates ?

Recommended Posts

f001error    122
G'day Does anyone know if its possible to use 'extern' pointers when the class the pointer points at uses a class template. IE the class the pointer points at is declared as class MyClass : public MyTemplate<MyClass > { ... }; and we use extern MyClass* PtrMyClass; to declare the variable I can get extern pointers working just fine if they point a normal class, but as soon as I use a class that uses a template it doesnt work. I know the template is written correctly, because the class works fine otherwise. This problem has been driving me nuts all day. Here's the vague compile time error messages when using a class derived from a template class. On the "MyClass* PtrMyClass;" Line error C2143: syntax error : missing ';' before '*' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C4430: missing type specifier - int assumed. Note: C++ does not support default-int On the "class MyClass : public MyTemplate<MyClass > {" line error C2923: 'MyTemplate' : 'MyClass ' is not a valid template type argument for parameter 'T' : see declaration of 'MyClass ' error C2955: 'MyTemplate' : use of class template requires template argument list : see declaration of 'MyTemplate'

Share this post


Link to post
Share on other sites
ToohrVyk    1595
Quick answer: yes, since the class is a type just like any other type. The following compiles on g++:

template<class A> class T { };
class B : public T<B> { };
extern B * b;




What is the definition of MyTemplate?

Share this post


Link to post
Share on other sites
JohnBolton    1372
Quote:
Original post by f001error
error C2143: syntax error : missing ';' before '*'

This is probably because the compiler doesn't know what MyClass is. Did you forget to include the header files that contain the declarations of MyClass and MyTemplate? The other errors are likely to be related though it is really hard to tell without seeing the relevant code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this