Re: Weird V-table issue
On Jul 29, 1:52 am, harsh.mur...@gmail.com wrote:
Thanks for all the replies. I do understand that the standard
way of doing things is to use virtual inheritance and dynamic
casting. However, I would like to clarify that I am working
on an embedded environment (and due to some other reasons
which I do not want to detail here), and I am restricted to
using non-virtual inheritance and no dynamic casting.
Further clarification on QueryInterface: I would like to
define a generic method which all the other interfaces
inherit. All the implementation objects implement the
QueryInterface() method to return the interfaces they they
implement. In such a scenario, the out- parameter of the
QueryInterface has to be a void **.
Why? In order to use the result, the user must know the type.
Maybe some sort of template function is what you're looking for:
class Network ...
{
public:
template< typename Interface >
bool queryInterface( Interface** result )
{
*result = this ;
return true ;
}
// ...
} ;
The problem with your code is that the QueryInterface throws
away information that the function needs in order to perform
correctly. Consider something like:
INetworkA* pA ;
INetworkB* pB ;
netObj->queryInterface( (void**)pA ) ;
netObj->queryInterface( (void**)pB ) ;
The actual addresses of the INetworkA and INetworkB subclasses
of the Network are different; how can queryInterface know which
one to return if you don't tell him which one is needed. (With
the template version, above, you wouldn't use the (void**) cast,
and two different functions would be called.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34