U
Ulrich Heinen
Hello,
I'm having trouble with a template member function in a non template class.
The attached sample program compiles and works just fine with GCC or IBM
VisualAge compilers but Sun Workshop 6 (C++ 5.1) doesn't like it. Am I
doing something illegal that accidentally works on the two first compilers
or is it the Sun compiler that gets it wrong?
The sun compiler stumbles over the indicated line with the message "Badly
formed expression."
Can anybody point me in the right direction? Thanks!
Ulrich
#include <cstdlib>
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;
class A {
public:
A(const char * name) : _name(name) {}
template<typename T> void test() const {
cout << _name << ": "<< typeid(T).name() << endl;
}
private:
string _name;
};
int main(int /*argc*/, char ** /*argv*/) {
A m("Hello");
m.test(); // this is the line the Sun compiler stumbles over
return EXIT_SUCCESS;
}
I'm having trouble with a template member function in a non template class.
The attached sample program compiles and works just fine with GCC or IBM
VisualAge compilers but Sun Workshop 6 (C++ 5.1) doesn't like it. Am I
doing something illegal that accidentally works on the two first compilers
or is it the Sun compiler that gets it wrong?
The sun compiler stumbles over the indicated line with the message "Badly
formed expression."
Can anybody point me in the right direction? Thanks!
Ulrich
#include <cstdlib>
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;
class A {
public:
A(const char * name) : _name(name) {}
template<typename T> void test() const {
cout << _name << ": "<< typeid(T).name() << endl;
}
private:
string _name;
};
int main(int /*argc*/, char ** /*argv*/) {
A m("Hello");
m.test(); // this is the line the Sun compiler stumbles over
return EXIT_SUCCESS;
}