class Scope: public BaseClass {
public:
template <class T>
T * GetData();
};
RestoreHandle::pList = pScope->GetData<HandleList>(); // <= Error
However, I get the following compilation error:
"error C2275: 'HandleList' : illegal use of this type as an expression"
If I put int instead of HandleList, I get the error:
"error C2062: type 'int' unexpected"
Why I get errors?
Template method
I have the following code:
I'm guessing it's because pScope is of type BaseClass * and BaseClass contains a non-template member function GetData. So you're trying to provide a template parameter to a non-template function. Are you trying to override a virtual function with a template function? If so, it can't be done.
Enigma
Enigma
Maybe visual C++ 6 doesnt support such tempates?
I really need help with this, my work is stuck because of this.
I really need help with this, my work is stuck because of this.
Quote:Original post by SiCrane
MSVC 6 does not support templated member functions.
It does, it just doesn't support defining them outside of the class definition. The following compiles just fine in MSVC 6.0
template <typename TT>class Test{public: template <typename T> void test(T t) { i = t; }private: TT i;};int main(void){ Test<int> t; t.test(0); return 0;}
Quote:Original post by mfawcettQuote:Original post by SiCrane
MSVC 6 does not support templated member functions.
It does, it just doesn't support defining them outside of the class definition. The following compiles just fine in MSVC 6.0
*** Source Snippet Removed ***
No it doesnt.
I have tried that as well.
Quote:Original post by The C modest godQuote:Original post by mfawcettQuote:Original post by SiCrane
MSVC 6 does not support templated member functions.
It does, it just doesn't support defining them outside of the class definition. The following compiles just fine in MSVC 6.0
*** Source Snippet Removed ***
No it doesnt.
I have tried that as well.
I tried it before I posted. I just tried it again. It compiles fine.
The problem with MSVC++ 6 is both that the template definition needs to appear inside of the class definition and also that it can't handle member function templates whose template parameters are explicitly specified. In other words, the difference between mfawcett's example and your example is that his template arguments are deduced by the function argument whereas in yours, you are specifying the template argument.
The only way around this in MSVC++ 6 is to make your function take a dummy parameter whose purpose is to help the compiler deduce the template arguments:
The only way around this in MSVC++ 6 is to make your function take a dummy parameter whose purpose is to help the compiler deduce the template arguments:
template< typename TemplateArgument >struct template_argument{};class Scope: public BaseClass { public: template <class T> T * GetData( template_argument< T > dummy ) { return new T; }};int main(){ Scope blah; int* a = blah.GetData( template_argument< int >() ); delete a;}
Just use out parameters instead of return values in MSVC6:
class Scope: public BaseClass { public: template <class T> GetData(T *& t);};pScope->GetData(RestoreHandle::pList);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement