A
aaragon
Hi everyone, I've been trying to compile a very simple code for
template partial specializatoin. I can't compile this code! what is
wrong with it? I'm using the g++ compiler.
#include <vector>
#include <iostream>
using namespace std;
template <class T, class U>
class ClassA
{
T t_;
U u_;
public:
ClassA() { t_ = 0; u_ = 0; }
void print()
{
cout<<"T -> "<<t_<<endl;
cout<<"U -> "<<u_<<endl;
}
};
template <class T>
void ClassA<T,int>:
rint()
{
cout<<"T -> "<<t_<<endl;
cout<<"U is an integer!"<<endl;
}
int main()
{
ClassA<double,int> ca;
ca.print();
return 0;
}
main2.cxx:25: error: invalid use of undefined type 'class ClassA<T,
int>'
main2.cxx:8: error: declaration of 'class ClassA<T, int>'
main2.cxx:25: error: template definition of non-template 'void
ClassA<T, int>:
rint()'
main2.cxx: In member function 'void ClassA<T, int>:
rint()':
main2.cxx:27: error: 't_' was not declared in this scope
template partial specializatoin. I can't compile this code! what is
wrong with it? I'm using the g++ compiler.
#include <vector>
#include <iostream>
using namespace std;
template <class T, class U>
class ClassA
{
T t_;
U u_;
public:
ClassA() { t_ = 0; u_ = 0; }
void print()
{
cout<<"T -> "<<t_<<endl;
cout<<"U -> "<<u_<<endl;
}
};
template <class T>
void ClassA<T,int>:
{
cout<<"T -> "<<t_<<endl;
cout<<"U is an integer!"<<endl;
}
int main()
{
ClassA<double,int> ca;
ca.print();
return 0;
}
main2.cxx:25: error: invalid use of undefined type 'class ClassA<T,
int>'
main2.cxx:8: error: declaration of 'class ClassA<T, int>'
main2.cxx:25: error: template definition of non-template 'void
ClassA<T, int>:
main2.cxx: In member function 'void ClassA<T, int>:
main2.cxx:27: error: 't_' was not declared in this scope