C++学习,第三十三课
已有 529 次阅读2014-8-26 08:54
|个人分类:作业
#include<iostream>
#include<string>
class Company
{
public:
Company(std::string theName);
virtual void print();
protected:
std::string name;
};
class TecCompany :public Company
{
public:
TecCompany(std::string name, std::string theproduct);
virtual void print();
private:
std::string product;
};
Company::Company(std::string theName)
{
name=theName;
}
TecCompany::TecCompany(std::string theName, std::string product) :Company(theName)
{
this->product = product;
}
void Company::print()
{
std::cout << "我是" << name << "公司\n\n";
}
void TecCompany::print()
{
std::cout << "我是" << name << "公司,我的产品是:" << product<<"\n\n";
}
int main()
{
Company *company = new Company("Microsoft");
company->print();
delete company;
company = NULL;
company = new TecCompany("Apple","iPad");
company->print();
delete company;
company = NULL;
system("pause");
return 0;
}