partial template specialization...

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>::print()
{
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>::print()'
main2.cxx: In member function 'void ClassA<T, int>::print()':
main2.cxx:27: error: 't_' was not declared in this scope
 
I

Ian Collins

aaragon said:
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.
You can't have partial specialisation of a class member, you can define
a specialisation of a member, or a partial specialisation of a class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top