By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

partial template specialization...

P: n/a
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,intca;
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

Nov 4 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
aaragon wrote:
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.

--
Ian Collins.
Nov 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.