Re: [Dev-C++] accessing derived class methods
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Richard M. <mu...@cs...> - 2005-09-20 14:10:51
|
This is straightforward C++. The base class pointers can only accesses those functions defined in the base class. If you want to access stuff unique to specific type of employee you'll have to make sure those pointers are, indeed, to that kind of object. Which you can't know ahead of time if all you have is a pointer to the base class. Getting those pointers is another issue. You can always do one of the various casts, in your case a dynamic_cast is probably the right thing, but this is chancy. The trick is to design your employee base class so that everything you need to do in terms of interface is defined in the base class. Dick Munroe >Message: 1 >To: dev...@li... >From: Dane Ensign <dg...@wo...> >Date: Mon, 19 Sep 2005 20:38:42 -0600 >Subject: [Dev-C++] accessing derived class methods > >Hi all, > >I have a simple base class and a few derived classes from it. My goal >is to build an array of pointers where I can assign derived class >objects into, then access the different derived class attributes >as needed. > >So I have an employee class. I derive a laborer, scientist, and >manager class from it. I build some basic virtual functions in the >employee class, and each derived class >has a couple of specific attributes that I want to call, like >getSpecificData(). > >I made an array of base class pointers then tried accessing the >derived class methods, but it doesnt work. I made an array of void* >pointers and tried to access derived class methods and that doesnt work. > >I realize that I could build a pure virtual function in the base >class that would only be used to access derived class atrributes, but >that is silly. Please can someone point* me in the right direction? > >Thanks for any help you can offer. > >Best regards, > >Dane >da...@de... > > > > > >--__--__-- > >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > >End of Dev-cpp-users Digest > > > > |