templates for class member functions
sorry this is not a boost question, but wondering whether you guys could help with templates. I want to place template parameters on a class's member function. however it does not work: class Test { public: template <class T> void DoTest(T t) { cout << t; } }; Test t; t.DoTest<int>(2); //error C2062: type 'int' unexpected is it possible to do this?
On 7/15/06, bringiton bringiton
sorry this is not a boost question, but wondering whether you guys could help with templates. I want to place template parameters on a class's member function. however it does not work:
class Test { public: template <class T> void DoTest(T t) { cout << t; } };
Test t; t.DoTest<int>(2); //error C2062: type 'int' unexpected
is it possible to do this?
aah, someone said this works on 7.1 im using ms vc++ 6 maybe time to upgrade my compiler ;)
bringiton bringiton wrote:
On 7/15/06, bringiton bringiton
wrote: sorry this is not a boost question, but wondering whether you guys could help with templates. I want to place template parameters on a class's member function. however it does not work:
class Test { public: template <class T> void DoTest(T t) { cout << t; } };
Test t; t.DoTest<int>(2); //error C2062: type 'int' unexpected
is it possible to do this?
aah, someone said this works on 7.1 im using ms vc++ 6
maybe time to upgrade my compiler ;)
Yes, you need to. vc6 has bugs with member templates that were never fixed AFAIK. There was one, as I recall, where something like what you are doing would compile incorrectly leading to nasty, hard to debug runtime errors... Jeff
bringiton bringiton wrote: ...
aah, someone said this works on 7.1 im using ms vc++ 6
maybe time to upgrade my compiler ;)
Unless you have to work with a lot of legacy code, there is no excuse for not upgrading all the way to 8.0. I wouldn't waste my time with 7.1. You can download VC++ Express (which is just Visual Studio but only for C++) for free from Microsoft. I've hated the older versions of VC++, but VC++ Express is great. It's free, compiles everything I throw at it, does it quickly, and generates fast code. What more can you ask for?
participants (4)
-
Artem Alimarine
-
bringiton bringiton
-
Deane Yang
-
Jeff Garland