|
-
May 9th, 2010, 08:38 PM
#1
virtual function question
I had a question about base classes that have virtual functions. If we have base class shape and then there is a derive class object rectangle with additional member length.
And we define
shape *s= new rectangle;
int length= s->length;
Will this work if length is an integer and public member of derived class rectangle and shape is pure abstract class?
-
May 10th, 2010, 02:50 AM
#2
Re: virtual function question
No. It won't. The Sahpe class doesn't know anything about the length member.
-
May 10th, 2010, 10:42 AM
#3
Re: virtual function question
The concept is virtual function, and not virtual member. You cannot have data-member as virtual.
Also, the function must be defined in base class as virtual.
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
|