using subclass functions

Hello

is it possible to access a subclass function if i use an array of pointers with the same type as the base class?

Example
1
2
3
4
5
6
BaseClass**b = new BaseClass*[10];

b[0] = new SubClass();

b[0]->//Use a subclass public member function 
You can only use functions declared in the base class.
If you need different behaviours for derived classes you have the option of overriding virtual functions.
http://www.cplusplus.com/doc/tutorial/polymorphism/
If you really need to access the derived class specific members, you'll need to cast b[0] to a pointer to SubClass.
http://www.cplusplus.com/doc/tutorial/typecasting/
Topic archived. No new replies allowed.