Posted on 2011-02-28 16:28
點點滴滴 閱讀(208)
評論(0) 編輯 收藏 引用 所屬分類:
02 編程語言
class test1
{
public:
virtual void animation()
{
cout << "test1 animation" << endl;
}
virtual void animation1() = 0;
};
class test2 : public test1
{
public:
virtual void animation1()
{
cout << "test2 animation1" << endl;
}
void animation()
{
cout << "test2 animation" << endl;
}
};
class test3 :public test2
{
void animation1()
{
cout << "test3 animation1" << endl;
}
void animation()
{
cout << "test3 animation" << endl;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
// allocatePractice();
test1* test = new test3();
test->animation();
test->animation1();
// //定義
// std::pair<int, string> ming(1,"ming1");
// std::map<int ,string> authors;
// //插入
// authors.insert(make_pair(3,"ming3"));
// authors.insert(map<int, string>::value_type(2,"ming2"));
// authors.insert(ming);
//
// cout << authors[4] << endl;
return 0;
}
virtual 為重載關鍵字,父類方法加上這個關鍵字,可以實現重載
輸出:
test3 animation
test3 animation1