Jump to content
  • Advertisement
Sign in to follow this  
programci_84

A complex inheritance problem

This topic is 2610 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!