D
dascandy
Hi,
For a project I'm working on I'm kind-of-hacking my way around
deriving a class from an interface or such to create a mock, but
instead creating the mock directly. It is usable as the interface type
(as the virtual functions match up), but there is a snag. No members
are initialized, which means it can't be used as the original type if
it has anything but virtual functions. It would be possible to make it
work, if I could call the constructor for the original type, but
because the functions are pure virtual that's not allowed. Deriving
from it would work, but requires me to fill in all the pure virtual
functions with some kind of random function only to never use them.
The last solution also requires you to un-pure-virtualize all the
classes you want to mock just for testing, which seems like a really
bad idea since it is a *lot* more to type.
Is there some kind of hackish or at least usable way of calling the
constructor regardless of pure virtual functions?
Thanks in advance,
Peter Bindels
For a project I'm working on I'm kind-of-hacking my way around
deriving a class from an interface or such to create a mock, but
instead creating the mock directly. It is usable as the interface type
(as the virtual functions match up), but there is a snag. No members
are initialized, which means it can't be used as the original type if
it has anything but virtual functions. It would be possible to make it
work, if I could call the constructor for the original type, but
because the functions are pure virtual that's not allowed. Deriving
from it would work, but requires me to fill in all the pure virtual
functions with some kind of random function only to never use them.
The last solution also requires you to un-pure-virtualize all the
classes you want to mock just for testing, which seems like a really
bad idea since it is a *lot* more to type.
Is there some kind of hackish or at least usable way of calling the
constructor regardless of pure virtual functions?
Thanks in advance,
Peter Bindels