This code is a tutorial, from internet, I can make it to compile,
error to advance for me, (+) use is a ???? for me, using MV C++.
Is a class tutorial.....
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
class Food
{
private:
//instance variable.Every object wiil have this variables.....
string mFoodName;
double mFoodPrice;
//class variable.Will be only one for the class.....
static int sCount;
public:
Food(string mFoodName = "Steak", double mFoodPrice = 13.67);
//Copy Constructor...................
Food(Food &food){
sCount++;
mFoodName = food.mFoodName;
mFoodPrice = food.mFoodPrice;
cout << " Food HI Copy Constructor : " + mFoodName << endl;
}
~Food(){
sCount--;
cout << " Food BYE Destructor: " + mFoodName + " " << sCount << endl;
}
void Display();
void ChangeFood(string foodName, double foodPrice){
mFoodName = foodName;
mFoodPrice = foodPrice;
}
};
//initialaze class variable........outside of class
int Food::sCount = 0; // with the scope resolute indicator(::) to indicate scount is variable of Food class.
void ModifyFood(Food &food);
Food ChangeFood(Food food);
int main(void)
{
Food f1;
Food f2("Ham");
Food f3("Chicken", 6.54);
ModifyFood(f2);
f1.Display();
f2.Display();
f3.Display();
Food f5 = ChangeFood(f3);
f5.Display();
Food f4 = f2;
f4.Display();
cout << " Leave main() " << endl << endl;
system("pause");
return 0;
}
void ModifyFood(Food &food){
cout << " Enter ModifyFood() " << endl;
food.Display();
food.ChangeFood("Pork Chops", 5.77);
cout << " Leave ModifyFood() " << endl << endl;
}
Food ChangeFood(Food food){
cout << " Enter ChangeFood() " << endl;
food.ChangeFood("Prime Rib", 16.54);
food.Display();
cout << " Leave ChangeFood() " << endl << endl;
return food;
}