template<int p> class A {
public:
int foo();
};
template<> class A<1> {
public:
int foo() {
return 1;
}
};
template<> class A<2> {
public:
int foo() {
return 2;
}
};
int main(int argc, char** argv){
A<1> a1;
A<2> a2;
A* a3 = &a2;
std::cout << a1.foo() << std::endl << a2.foo() << std::endl << a3->foo() << std::endl;
return 0;
}
#include <iostream>
class AA {
public:
virtual int foo() = 0;
};
template<int p> class A : public AA {};
template<> class A<1> :public AA {
public:
int foo() {
return 1;
}
};
template<> class A<2> : public AA {
public:
int foo() {
return 2;
}
};
int main(int argc, char** argv){
A<1> a1;
A<2> a2;
AA* a3 = &a2;
std::cout << a1.foo() << std::endl << a2.foo() << std::endl << a3->foo() << std::endl;
return 0;
}