Jump to content

  • Log In with Google      Sign In   
  • Create Account

A complex inheritance problem


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 programci_84   Members   -  Reputation: 335

Like
0Likes
Like

Posted 22 October 2011 - 09:25 AM

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.

Sponsor:

#2 irreversible   Crossbones+   -  Reputation: 1344

Like
1Likes
Like

Posted 22 October 2011 - 10:01 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS