I'm not 100% sure on implementation, but you could have multiple 'vtables' for a derived object pointing to different member functions in the derived class (that's likely how this is implemented at least in langauges that allow for multiple interface inheritance) -- perhaps a more clever implementation of multiple inheritance builds a single table with the derived member functions however.
If I don't override a base function, is vtable still created for my derived class? Or only the pointer is inherited and points straight to the base vtable? For instance: class Base { public: virtual void swim() {} } class Derived: public Base {} Derived derived;
As soon as you introduce 'virtual' or 'override' in a class a vtable (or some mechanism to achieve polymorphism) is created. In this instance, If you make a call to 'swim' from the derived class, then we'll be looking into Base's vtable to call the appropriate swim. So while it's probably implementation defined (i.e. up to the compiler), I would assume this example generates a vtable.
The way I would probably answer this is that we need an object to be fully constructed (including its vtable for later redirection) before we can do anything with it. Probably best to hear it from Bjarne himself www.stroustrup.com/bs_faq2.html#virtual-ctor
Virtual functions work based on the vtable mechanism, which is set up after the constructor finishes executing.Moreover, there's no need for constructors to be virtual. When an object is created, the constructor of the specific class is known at compile time, and there's no ambiguity about which constructor to call.
Hi, I am strugling with this vtable error. Please help Below is the arduino code for ePaper display. #include #include //2.13" E-paper Module (White/Red/Black) #include #include #include GxIO_Class io(SPI, SS, 17, 16); GxEPD_Class display(io, 16, 4); void setup() { } void loop() { } Here is the error below undefined reference to `vtable for GxIO' collect2.exe: error: ld returned 1 exit status exit status 1 Compilation error: exit status 1
you are a best teacher
@@Gaspardkirira Thank you for the kind words 🙏
Great video. Very neatly explained as always. Thank you.
Thank you i waited for this topic for long its crystal clear now.
You are most welcome!
kudos for your hardwork. But it's difficult to understand, can you explain again with good diagrams?
Cheers! See around 2 minute mark for some pictures
What's the link with the multiple inheritance vtables mentioned at the end?
I'm not 100% sure on implementation, but you could have multiple 'vtables' for a derived object pointing to different member functions in the derived class (that's likely how this is implemented at least in langauges that allow for multiple interface inheritance) -- perhaps a more clever implementation of multiple inheritance builds a single table with the derived member functions however.
Great video! Thanks Mike.
You are most welcome!
virtual pointer and virtual table are part of class. So what is the type of virtual pointer and virtual table?
I believe the virtual table is of type void** (a pointer to a table of pointers)
@@MikeShahMay I know, why void?
@@kunalkumar-ic1dc It's merely holding an address, no 'type' associated with it.
@@MikeShah Thanks for the clarification.
If I don't override a base function, is vtable still created for my derived class? Or only the pointer is inherited and points straight to the base vtable? For instance:
class Base {
public:
virtual void swim() {}
}
class Derived: public Base {}
Derived derived;
As soon as you introduce 'virtual' or 'override' in a class a vtable (or some mechanism to achieve polymorphism) is created. In this instance, If you make a call to 'swim' from the derived class, then we'll be looking into Base's vtable to call the appropriate swim. So while it's probably implementation defined (i.e. up to the compiler), I would assume this example generates a vtable.
@@MikeShah Thanks! :)
@@grenadier4702 Cheers!
@@AlberTesla1024 I believe that is true
thanx bro . love y0ou=
Is that vim please? I need to settle smth
sorry it's late and i didn't notice, kudos to you for that
Cheers! @@zizicz1661 (This might be relevant as well! th-cam.com/video/e4E6nQpd7Xs/w-d-xo.html)
why destuctors have to be virtual and constructors can't be virtual, I was asked this once in an interviews, still not sure I have realize an answer.
The way I would probably answer this is that we need an object to be fully constructed (including its vtable for later redirection) before we can do anything with it. Probably best to hear it from Bjarne himself www.stroustrup.com/bs_faq2.html#virtual-ctor
@@MikeShah cool thanks.
Virtual functions work based on the vtable mechanism, which is set up after the constructor finishes executing.Moreover, there's no need for constructors to be virtual. When an object is created, the constructor of the specific class is known at compile time, and there's no ambiguity about which constructor to call.
thanks alot
Cheers!
nice
Cheers!
Hi, I am strugling with this vtable error. Please help
Below is the arduino code for ePaper display.
#include
#include //2.13" E-paper Module (White/Red/Black)
#include
#include
#include
GxIO_Class io(SPI, SS, 17, 16);
GxEPD_Class display(io, 16, 4);
void setup() {
}
void loop() {
}
Here is the error below
undefined reference to `vtable for GxIO'
collect2.exe: error: ld returned 1 exit status
exit status 1
Compilation error: exit status 1
cool
Cheers!
2 ведра воды о полиморфизме
too slow
Dude, use a slide show or something rather than writing.