?? 5_13.cpp
字號:
#include <iostream>
using namespace std;
class Cylinder; // 前向引用聲明
enum Colors { red, green, yellow }; //定義顏色枚舉類型
class Cube
{ Colors color;
public:
Cube(Colors c) { color = c; }
friend bool TestSame(Cube x, Cylinder y); //聲明為Cube的友元函數
};
class Cylinder
{ Colors color;
public:
Cylinder(Colors c) { color= c; }
friend bool TestSame(Cube x, Cylinder y); //聲明為Cylinder的友元函數
};
bool TestSame(Cube x, Cylinder y) { if(x.color == y.color) return true; else return false; }
int main()
{ Cube cube1(red), cube2(yellow); Cylinder cyl(yellow); //聲明對象并初始化
if(TestSame(cube1, cyl)) cout << "The color of cube1 and cyl are the same.\n";
else cout << "The color of cube1 and cyl are different.\n";
if(TestSame(cube2, cyl)) cout << "The color of cube2 and cyl are the same.\n";
else cout << "The color of cube2 and cyl are different.\n";
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -