同一段代码在VC++6.0上面能编译并运行,而到vc++8.0上面就只能编译通过,而不能运行了!这是为什么??
以下代码在VC++8.0中能编译通过,可是却不能运行,这是为什么??
# include <iostream>
using namespace std;
template<class type>
class Sample
{
protected:
type Tn;
public:
Sample(type T)
{
Tn=T;
}
friend bool operator==(Sample&,Sample&);
void dispaly()const
{
cout<<Tn<<endl;
}
};
template<class type>
bool operator==(Sample<type>& s1,Sample<type>& s2)
{
if(s1.Tn==s2.Tn)
return true;
else return false;
}
void main(void)
{
Sample<int>S1(10),S2(20),S3(10);
cout<<"S1==";
S1.dispaly();
cout<<"S2==";
S2.dispaly();
cout<<"S3==";
S3.dispaly();
if(S1==S2) cout<<"S1==S2"<<endl;
else cout<<"S1!=S2"<<endl;
if(S1==S3) cout<<"S1==S3"<<endl;
else cout<<"S1!=S3"<<endl;
Sample<char>S4('a'),S5('b'),S6('a');
cout<<"S4==";
S4.dispaly();
cout<<"S5==";
S5.dispaly();
cout<<"S6==";
S6.dispaly();
if(S4==S5) cout<<"S4==S5"<<endl;
else cout<<"S4!=S5"<<endl;
if(S4==S6) cout<<"S4==S6"<<endl;
else cout<<"S4!=S6"<<endl;
}