Re: Polymorphism without virtual in C++
"feel" <feelapi@gmail.com> wrote in message
news:35702afc-3c74-4ab2-abea-f1ea08a8da78@t1g2000pra.googlegroups.com...
On 8???8???, ??????4???17???, James Kanze <james.ka...@gmail.com> wrote:
[...]
Thank you for your reply. I think you are right. I do not use virtual
functions as interface
because the size of object. Saying line, we can put two points as data
implementation. But if
put many virtual functinos into class, we have to get a bigger object
than that object should be:
only two points!Object's size is very important in geometry class
design.
Pimpl can make sure the object's size is suitable for this
requirements.
Polymorphism means in this case is like this: we can call curve's
getLength() function to get curve's
length. but for different kind of curves, we have to implementation
different method to compute it.
Some implementations can have a huge vtable, but the size of the object is
going to be a pointer to the vtable:
class Interface {
virtual void func1() = 0;
virtual void func2() = 0;
virtual void func3() = 0;
virtual void func4() = 0;
virtual void func5() = 0;
virtual void func6() = 0;
virtual void func7() = 0;
virtual void func8() = 0;
[on and on...];
virtual ~Interface() = 0;
};
Interface::~Interface() {}
could end of resulting in:
sizeof(Interface) == sizeof(void*);
on some impls...