template <class T>;
class ReferencePointer {
};
template <>
class ReferencePointer<Scope> {
};
But I get the errors:
C2908: explicit specialization; 'ReferencePointer<T>' has already instantiated with [ T=Scope ]
C2766: explicit specialization; 'ReferencePointer<Scope>' has already been defined
What am I doing wrong?
[Edited by - The C modest god on October 2, 2006 9:43:05 AM]
Template specialization error
I have a template class, and I try that for a certain class (T=Scope) the template will behave differently.
So I did:
You declared the first template incorrectly. Try this:
template <class T>
class ReferencePointer {
};
template <>
class ReferencePointer<Scope> {
};
template <class T>
class ReferencePointer {
};
template <>
class ReferencePointer<Scope> {
};
Quote:Original post by Dranith
You declared the first template incorrectly. Try this:
template <class T>
class ReferencePointer {
};
template <>
class ReferencePointer<Scope> {
};
Sorry, you are right.
I just wrote it wrong, my original code didnt had this problem.
So the error I get is also valid for this too.
Well, my next guess would be that you are including the header that defines this template in multiple files, but you forgot to add a header guard. This is usually the problem when you get those "already defined" errors when dealing with classes defined in headers.
If it isn't that, then I have no clue without seeing more of the code.
If it isn't that, then I have no clue without seeing more of the code.
I don't think you can actually specialize a class like that; class specialization must be done by specializing the member functions IIRC.
Quote:Original post by omgomghilol
I don't think you can actually specialize a class like that; class specialization must be done by specializing the member functions IIRC.
Both are possible, though mutually exclusive.
The following code compiles okay for me.
This is the way you have to specialize template classes in C++.
Your error is not in the code you posted. The error is in the code you did not post. Check your include guards.
class Scope{};template <class T>class ReferencePointer {};template <>class ReferencePointer<Scope> {};main(){ ReferencePointer<Scope> p;}
This is the way you have to specialize template classes in C++.
Your error is not in the code you posted. The error is in the code you did not post. Check your include guards.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement