P
PengYu.UT
Hi,
"call()" calles "show()". I got some error as indicated below in the
comments. I tried to delete the definition and declaration of "call()"
and call "show()" in the main() body, then it got compiled. I'm not
sure what's wrong with the following code. Would you please help me to
fix it?
Best wishes,
Peng
#include <iostream>
#include <complex>
template <typename Tp>
class A{
public:
A(){};
void call();
void show();
};
template <>
void A<int>::call(){
A<int>::show();
}
template <>
void A<double>::call(){
A<double>::show();
}
template <>
void A<double>::show(){//get compile error here
std::cout << "double" << std::endl;
}
template <>
void A<int>::show(){
std::cout << "int" << std::endl;
}
int main(int argc, char *argv[]) {
A<double> a;
A<int> b;
a.call();//a.show();
b.call();//b.show();
}
"call()" calles "show()". I got some error as indicated below in the
comments. I tried to delete the definition and declaration of "call()"
and call "show()" in the main() body, then it got compiled. I'm not
sure what's wrong with the following code. Would you please help me to
fix it?
Best wishes,
Peng
#include <iostream>
#include <complex>
template <typename Tp>
class A{
public:
A(){};
void call();
void show();
};
template <>
void A<int>::call(){
A<int>::show();
}
template <>
void A<double>::call(){
A<double>::show();
}
template <>
void A<double>::show(){//get compile error here
std::cout << "double" << std::endl;
}
template <>
void A<int>::show(){
std::cout << "int" << std::endl;
}
int main(int argc, char *argv[]) {
A<double> a;
A<int> b;
a.call();//a.show();
b.call();//b.show();
}