P
PengYu.UT
I have the following two program. The first one compiles well, but the
second one doesn't. The only difference between them is one more
template parameter is added for the second program.
Would you please help on how to make the second program work?
Thanks,
Peng
/************first************************/
#include <iostream>
class tag1;
class tag2;
template <typename T>
class A{
public:
void print();
};
template <>
void A<tag1>:rint() {
std::cout << "tag1" << std::endl;
}
template <>
void A<tag2>:rint() {
std::cout << "tag2" << std::endl;
}
int main(int ac, char* av[])
{
A<tag1> a1;
a1.print();
A<tag2> a2;
a2.print();
}
/************end first************************/
/**************second*************************/
#include <iostream>
class tag1;
class tag2;
template <typename T1, typename T>
class A{
public:
void print();
};
template <typename T1>
void A<T1, tag1>:rint() {
std::cout << "tag1" << std::endl;
}
template <typename T1>
void A<T1, tag2>:rint() {
std::cout << "tag2" << std::endl;
}
int main(int ac, char* av[])
{
A<int, tag1> a1;
a1.print();
A<int, tag2> a2;
a2.print();
}
/**************end second*************************/
second one doesn't. The only difference between them is one more
template parameter is added for the second program.
Would you please help on how to make the second program work?
Thanks,
Peng
/************first************************/
#include <iostream>
class tag1;
class tag2;
template <typename T>
class A{
public:
void print();
};
template <>
void A<tag1>:rint() {
std::cout << "tag1" << std::endl;
}
template <>
void A<tag2>:rint() {
std::cout << "tag2" << std::endl;
}
int main(int ac, char* av[])
{
A<tag1> a1;
a1.print();
A<tag2> a2;
a2.print();
}
/************end first************************/
/**************second*************************/
#include <iostream>
class tag1;
class tag2;
template <typename T1, typename T>
class A{
public:
void print();
};
template <typename T1>
void A<T1, tag1>:rint() {
std::cout << "tag1" << std::endl;
}
template <typename T1>
void A<T1, tag2>:rint() {
std::cout << "tag2" << std::endl;
}
int main(int ac, char* av[])
{
A<int, tag1> a1;
a1.print();
A<int, tag2> a2;
a2.print();
}
/**************end second*************************/