partial template specialization...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • aaragon

    #1

    partial template specialization...

    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,i ntca;
    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

  • Ian Collins

    #2
    Re: partial template specialization. ..

    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.

    Comment

    Working...