Q: Inheritor class accessing base 
Author Message
 Q: Inheritor class accessing base

How does an inherited class access its parent class as an object.

Like the super() method in java?

for example
MyCDialog inherits from CDialog, which inherits from CWnd

for functions that I want to call in MyCDialog that required a CWnd object
passed, what do I do?

SomeFunction(CWnd* pCWnd)
casting doesnt work: SomeFunction((CWnd) pMyCDialog)

in java it would be
SomeFunction(super().super().super())

any help?
Thanks



Sun, 01 Apr 2001 03:00:00 GMT  
 Q: Inheritor class accessing base


Fri, 19 Jun 1992 00:00:00 GMT  
 Q: Inheritor class accessing base

Quote:

>for example
>MyCDialog inherits from CDialog, which inherits from CWnd

>for functions that I want to call in MyCDialog that required a CWnd object
>passed, what do I do?

>SomeFunction(CWnd* pCWnd)
>casting doesnt work: SomeFunction((CWnd) pMyCDialog)

Casting would work if you did right:
    SomeFunction((CWnd*) pMyCDialog);  /// You can't cast a pointer into an
object.

but it is unnecessary.  A pointer to an object is considered the same as a
pointer to a less derived class:

    SomeFunction(pMyCDialog);

--
Truth,
   James [MVP]
http://www.NJTheater.Com       -and-
http://www.NJTheater.Com/JamesCurran

begin 666 James M. Curran.vcf


M4DLZ.SLQ."!*;VAN(%-T+"!3=6ET92 R0CM";&]O;69I96QD.TY*.S W,# S
M+34Q-#D-"DQ!0D5,.U=/4DL[14Y#3T1)3D<]455/5$5$+5!224Y404),13HQ
M."!*;VAN(%-T+"!3=6ET92 R0CTP1#TP04)L;V]M9FEE;&0L($Y*(# W,# S
M+34Q-#D-"E523#IH='1P.B\O=W=W+DY*5&AE871E<BYC;VTO2F%M97-#=7)R
M86X-"E523#IH='1P.B\O=W=W+DY*5&AE871E<BYC;VT-"D5-04E,.U!2148[
M24Y415).150Z2F%M97-#=7)R86Y 0V]M<'5397)V92YC;VT-"E)%5CHQ.3DX

`
end



Sun, 01 Apr 2001 03:00:00 GMT  
 Q: Inheritor class accessing base


Fri, 19 Jun 1992 00:00:00 GMT  
 Q: Inheritor class accessing base
In C++ (and Java) an instance of an inherited class IS an instance of
the parent class. A MyCDialog IS a CDialog IS a CWnd, so it should be
a non-issue, e.g.

        MyCDialog* pMyCDialog = new MyCDialog ;
        SomeFunctionRequiringACWnd( pMyCDIalog ) ;

Your example of casting as written won't work, because your casting to
a CWnd not a CWnd*.

The only time this should come into play at all is when you want to
call the base class implementation of a function, as you see MFC do
all the time in message handlers. There you use the scope resolution
operator, e.g.

int MyCDialog::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
        if (CDialog::OnCreate(lpCreateStruct) == -1)
                return -1;
        // ...

Quote:
}

C++ has no way of referring to "the immediate parent class whatever it
might be."  This may be because the behavior would have to be
undefined for classes using multiple inheritance.

On Wed, 14 Oct 1998 11:56:16 -0400, "Ronaldo Nascimento"

Quote:

>How does an inherited class access its parent class as an object.

>Like the super() method in java?

>for example
>MyCDialog inherits from CDialog, which inherits from CWnd

>for functions that I want to call in MyCDialog that required a CWnd object
>passed, what do I do?

>SomeFunction(CWnd* pCWnd)
>casting doesnt work: SomeFunction((CWnd) pMyCDialog)

>in java it would be
>SomeFunction(super().super().super())

>any help?
>Thanks

Don Grasberger
(remove --- from address to e-mail)


Mon, 02 Apr 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Protected member in a base class of a base class

2. More Qs and Comments on UdpClient class

3. Accessing Base Class's control's events

4. Access memo fields from AppWizard CRecordset based classes

5. Error trying to access a derived member function from the base class

6. class class-name: base-class : interface

7. Trying to add a class with no base class in Class Wizard

8. ECC-based base class template code

9. VC++ class inheriting C# class loses base functions

10. TreeNode : Cast base class into sub class

11. Converting from Base Class to Sub-Class

12. How to Stop Derived Class from overriding base class method

 

 
Powered by phpBB® Forum Software