I think I understand the concept of virtual methods and vtables, but I don't understand why there is a difference between passing the object as a pointer(or reference) and passing it by value (which kind of scraps the vtable or something?)
Why would something like this work:
Material* m = new Texture;
poly->setMaterial(m);
// methods from Texture are called if I keep carrying the pointer around
And not this?:
Material m = Texture();
poly->setMaterial(m);
// methods from Material are called if I pass the value around
poly
and what does it have to do with anything? Where are your actual virtual calls? How come yoursetMaterial
method can accept both pointers and values? Is it overloaded? – Syndic