P
PengYu.UT
Hi,
The following program(doesn't compile) shows that I want to define
class A with different template arguments "int" and "double". Because
class A with int or with double are very different, I have define then
separately.
But it doesn't work. Could you show me the right way?
Best wishes,
Peng
#include <iostream>
template <int>
class A{
public:
A(){ std::cout << "int" << std::endl;}
};
template <double>
class A{
public:
A(){ std::cout << "double" << std::endl;}
};
int main(int argc, char *argv[]) {
A<int> a;
A<double> b;
}
The following program(doesn't compile) shows that I want to define
class A with different template arguments "int" and "double". Because
class A with int or with double are very different, I have define then
separately.
But it doesn't work. Could you show me the right way?
Best wishes,
Peng
#include <iostream>
template <int>
class A{
public:
A(){ std::cout << "int" << std::endl;}
};
template <double>
class A{
public:
A(){ std::cout << "double" << std::endl;}
};
int main(int argc, char *argv[]) {
A<int> a;
A<double> b;
}