Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to inherit from classes based on CDialog?

Status
Not open for further replies.

pr3mpo

Technical User
Apr 25, 2003
3
0
0
GB
Hi all,

Here’s a stupid question from a stupid VC++ beginner which I’m sure has an obvious solution, but not to me.

How do you implement inheritance with VC++? If you had class B, a child class of class A, in ordinary C++ you would just go: class B: public class A, etc. yeah?

In VC6 I’ve created an application with the MFC AppWizard, dialog based, in which I have a class, say CAccount, which I want to extend. As is normal I suppose CAccount’s base class is CDialog. I want to add CCurrentAccount, CSavingsAccount etc, which are child classes of CAccount. Is this possible? I can’t seem to find a way to do it.

Any help would be greatly appreciated.
 
Go to Insert->New Class. Then choose CDialog under Base Class
 
Thanks for that, but if I try to do that it doesn't really work.

What I want to do is have CAccount as the base class of CCurrentAccount rather than CDialog. If I chose insert-> new class, would that inherit all the attributes and methods I've set up in CAccount? If it does I'm missing something, because it doesn't in mine.

Sorry for being such a bother! Any help appreciated.
 
Try:

Insert->NewClass in the New Class popup change the class type to the one you want, generic class and then enter the name of the class you want. Click OK and the account should appear in the class view.
 
>> in ordinary C++ you would just go: class B: public class A, etc. yeah?

Exactly right, and there's nothing stopping you from doing that

Just make sure that the derived dialog classes all use the same dialog template resource as the base class.
 
When I add a new generic class based on CAccount, the new class shows in the class view, butwhen I try to allocate a dialog resource to it the class wizard doesn't list the new class in the list box.

>>Just make sure that the derived dialog classes all use the same dialog template resource as the base class.

How do you do this?

Thanks again in advance.
 
>> butwhen I try to allocate a dialog resource to it

Do you intend to use the same dialog resource for both classes?

If so, then there is no need to "allocate a dialog resource to it", because the derived dialog class will inherit the IDD constant from its base class.

If not, then the two dialogs are unrelated, and you shouldn't be deriving one from another.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top