|
-
May 8th, 2001, 11:50 AM
#1
Thread Starter
Junior Member
Inheritance in C++ (urgent)
I have a Class Account with some functions like
withdraw , deposit, Print as public functions
and I have also classes called Checking , Savings which are inherited from the above ones . I have overided the print function of Class Account in both Checking and Savings classes.
But my below code does not work properly.
Account *A[10];
A[1] = new Checking();
A[2] = new Savings();
When I reference A[1]->print() sometimes it is giving some error or just printing from Account but not coming from Checking or savings
Can Any one Help me
thanks
-
May 8th, 2001, 12:06 PM
#2
Thread Starter
Junior Member
inheritance in c++(urgent)
if my question was not clear please let me know
can Anyone help me in this ?
-
May 8th, 2001, 12:13 PM
#3
Monday Morning Lunatic
For this you need to use virtual inheritance, which I explained somewhere else....do a search for Base and Derived 
Make the public functions that get overridden virtual:
Code:
class Base {
public:
virtual void Print() { ... }
};
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 8th, 2001, 12:23 PM
#4
Thread Starter
Junior Member
Thanks,
I guess it works out
-
May 9th, 2001, 04:13 PM
#5
Frenzied Member
Like:
class CObject
{
public:
CObject();
~CObject();
virtual void draw() {}
};
class CCube : public CObject
{
public:
CCube();
~CCube();
void Draw()
{
// Drawing Code
}
};
Sorry if its a bit late etc but what the hell
-
May 9th, 2001, 04:15 PM
#6
Monday Morning Lunatic
Don't see why people put "C" in front of class names, but oh well 
Anyway, that's just normal inheritance. Virtual inheritance is calling a derived class member function through a base class pointer. The compiler magically knows to call the right one Cool really
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
May 9th, 2001, 04:21 PM
#7
Monday Morning Lunatic
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|