[問題] virtual的用法?
看板C_and_CPP (C/C++)作者rosemary0401 (rosemary0401)時間15年前 (2010/11/25 23:18)推噓6(6推 0噓 2→)留言8則, 7人參與討論串1/1
在使用virtual function上,小妹在網路上常看到兩種不同的版本
版本一:
class animal
{
public:
virtual void eat()
{
cout << "eat generic animal" << endl;
}
};
class cat : public animal
{
public:
void eat()
{
cout << "eat fish" << endl;
}
};
版本二:
class animal
{
public:
virtual void eat()
{
cout << "eat generic animal" << endl;
}
};
class cat : public animal
{
public:
virtual void eat()
{
cout << "eat fish" << endl;
}
};
請問哪個版本才是正確的呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.240.220.224
→
11/25 23:19, , 1F
11/25 23:19, 1F
推
11/25 23:21, , 2F
11/25 23:21, 2F
推
11/25 23:29, , 3F
11/25 23:29, 3F
推
11/26 00:48, , 4F
11/26 00:48, 4F
推
11/26 00:50, , 5F
11/26 00:50, 5F
→
11/26 01:19, , 6F
11/26 01:19, 6F
推
11/26 12:35, , 7F
11/26 12:35, 7F
推
11/26 13:14, , 8F
11/26 13:14, 8F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章