Re: grouping different kinds of food
From: JKop (NULL_at_NULL.NULL)
Date: 04/25/04
- Next message: Mark A. Gibbs: "Re: The Gist of Object Oriented Programming"
- Previous message: JKop: "Re: INCITS/ISO/IEC 14882:2003 vs INCITS/ISO/IEC 14882:1998"
- In reply to: news.hku.hk: "grouping different kinds of food"
- Next in thread: news.hku.hk: "Re: grouping different kinds of food"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 25 Apr 2004 14:24:23 GMT
class Fruit
{
public:
virtual char* GetName(void) const = 0;
virtual unsigned short int GetPrice(void) const = 0;
};
class Apple : public Fruit
{
public:
virtual char* GetName(void) const
{
return "Apple";
}
virtual unsigned short int GetPrice(void) const
{
return 23;
}
};
class Orange : public Fruit
{
public:
virtual char* GetName(void)
{
return "Orange";
}
virtual unsigned short int GetPrice(void)
{
return 17;
}
};
void DisplayFruitInfo(Fruit* f);
int main(void)
{
Apple a;
Orange b;
DisplayFruitInfo(&a);
DisplayFruitInfo(&b);
}
void DisplayFruitInfo(Fruit* f)
{
cout << "Name: " << f.GetName();
<< "\r\nPrice: " << f.GetPrice() << "\r\n";
}
That what you're looking for?
- Next message: Mark A. Gibbs: "Re: The Gist of Object Oriented Programming"
- Previous message: JKop: "Re: INCITS/ISO/IEC 14882:2003 vs INCITS/ISO/IEC 14882:1998"
- In reply to: news.hku.hk: "grouping different kinds of food"
- Next in thread: news.hku.hk: "Re: grouping different kinds of food"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|