int main(){
	Carp myLunch;
	Tuna myDinner;
	
	cout << "Getting my food to swim" << endl;
	
	cout << "Lunch: ";
	myLunch.Swim();
	
	cout << "Dinner: ";
	myDinner.Swim();

	// 取消此注释可以看到被保护的成员变量不可从类之外访问
	//myLunch.FreshWaterFish = false;	
	return 0;	
}
Esempio n. 2
0
int main()
{
    Carp myLunch;
    Tuna myDinner;

    cout << "Getting my food to swim" << endl;

    cout << "Lunch: ";
    myLunch.Swim();

    cout << "Dinner: ";
    myDinner.Swim();

    // uncomment line below to see that protected members
    // are not accessible from outside the class hierarchy
    // myLunch.FreshWaterFish = false;
    
    return 0;
}