A complex inheritance problem

Started by
0 comments, last by irreversible 12 years, 5 months ago
Hi all,

I can describe my problem only throug a sample code. Sorry for that.

I've a class inherited through IUnknown (and I want to hide some members):


//a1.h
#define _INTERFACE(IName) interface DECLSPEC_NOVTABLE IName : public IUnknown
#define _INTERFACE_(IName, IBase) interface DECLSPEC_NOVTABLE IName : public IBase

_INTERFACE(A1)
{
//AddRef(), Release(), QueryInterface() come here!

void A1_Func(float y);
};
////////// end of a1.h /////////////

//a1.cpp
struct A1_D : public A1
{
/* AddRef(), Release() and QueryInterface() definitons come here! */

float x;

ULONG _ref_count
};

inline A1_D* CImpl (A1* ptr) { return ( A1*)ptr; }
inline const A1_D* CImpl (const A1* ptr) { return (const A1*)ptr; }

void A1_Func(float y)
{
A1_D* pA1_D = CImpl(this);
pA1_D->x = y;
}
////////// end of a1.cpp /////////////


Now I want a class inherited through A1:


//a2.h
_INTERFACE_(A2, A1)
{
void A2_Func();
};
////////// end of a2.h /////////////

//a2.cpp
struct A2_D : public A2
{
/* AddRef() etc. definitons come here! */


};


It seems that A2::A1_Func() does not work properly.

How can I do this?

Hope I could explain.

Thanks in advance.
-R
There's no "hard", and "the impossible" takes just a little time.
Advertisement

It seems that A2::A1_Func() does not work properly.


Could you be a bit more specific - in what way? Is it not being called at all? If it isn't, then what is? Does it crash?

Two notes: in case you're overriding A1_Func() in any inherited class (which you're not showing in your code), then A1::A1_Func() needs to be virtual. Also, if A1_Func() is present in IUnknown, it needs to be virtual there. Other than that, in the code that you posted, the definition of A1_Func() is standalone as it is missing the class scope. In other words, in your posted code, your A1::A1_Func() has no body, which is something the compiler should tell you about.

This topic is closed to new replies.

Advertisement