代码:
1 #include <iostream> 2 3 using namespace std; 4 5 class B; 6 class A{ 7 public: 8 int i; 9 void fun1(){ 10 cout<<"I am A"<<endl; 11 } 12 }; 13 14 class B{ 15 public: 16 void fun(){ 17 cout<<"I am B"<<endl; 18 } 19 operator A(){}; 20 }; 21 22 int main(){ 23 24 B b; 25 b.fun(); 26 A a = b; 27 a.fun1(); 28 return 0; 29 }
输出;
I am B I am A
分析:
假如注释掉代码第19行,编译将会出错。