虚函数
信息来源: 牛津词典, LDOCE, TBBT
Our deputy manager is the virtual head of the business. 我们的副经理是公司的实际负责人。
class Homo_sapiens {
virtual void talk() = 0;
class Person : Homo_sapiens {
virtual void talk() { puts("我打酱油的。"); }
class Worker : Person {
virtual void talk() {
puts("Hei-you-hei-you, hei-you-hei-you");
puts("Ai-da-da-ai-da, ai-da-da-ai-da");
puts("Take the man down.")
}
class DeputyManager : Worker {
virtual void talk() {
puts("I'm the virtual head. How magnificent am I.");
puts("Hey! Less talk, more work!")
}
Homo_sapiens* hs1 = new Worker;
Homo_sapiens* hs2 = new DeputyManager;
hs1->talk();
hs1 = hs2;
hs1->talk();
delete hs2; hs1;
// no memory leak
virtual
1. very nearly a particular thing
2. made, done, seen etc on the Internet or on a computer, rather than in the real world
a. being or acting as what is described, but not accepted as such in name or officially 事实上的, 实际上的, 实质上的
virtually:
1. almost, pratically
2. on a computer, rather than in the real world
Virtual reality (VR) is a simulated experience that can be similar to or completely different from the real world. Applications of virtual reality include entertainment (e.g. video games) and education (e.g. medical or military training). Other distinct types of VR-style technology include augmented reality and mixed reality, sometimes referred to as extended reality or XR.
simulate, emulate, imitate, stimulate, stipulate, ...
串替换class为struct比一个个加public:方便。