我想我理解虚拟方法和 vtables 的概念,但我不明白为什么将对象作为指针(或引用)传递和按值传递(哪种废弃 vtable 或其他东西?)
为什么这样的事情会起作用:
Material* m = new Texture;
poly->setMaterial(m);
// methods from Texture are called if I keep carrying the pointer around
而不是这个?:
Material m = Texture();
poly->setMaterial(m);
// methods from Material are called if I pass the value around