我改了改,这样可以编译通过。但是和你的需求还是有点差异。
#include<iostream>
using namespace std;
struct S1{};
struct S2{};
struct S3{};
template<typename T1, typename T2>
class X
{
public:
void print(T2 &v){}
};
template<typename T1>
class X<T1, S1>
{
public:
void print(S1 &v){ cout << "S1" << endl; }
};
template<typename T1>
class X<T1, S2>
{
public:
void print(S2 &v){ cout << "S2" << endl; }
};
template<typename T1>
class X<T1, S3>
{
public:
void print(S3 &v){ cout << "S3" << endl; }
};
int main()
{
S1 s1;
S2 s2;
S3 s3;
X<int, S1> x1;
X<int, S2> x2;
X<int, S3> x3;
x1.print(s1);
x2.print(s2);
x3.print(s3);
return(0);
}
【 在 maxpi 的大作中提到: 】
: 代码:
: #include<iostream>
: using namespace std;
: ...................
--
FROM 219.143.130.*