-
October 8th, 2008, 02:02 AM
#1
Is there anything like Virtual Class present ?
Hi,
Is there any concept called 'Virtual Class' present in C++ ?
Thanks
Kiran
-
October 8th, 2008, 03:22 AM
#2
Re: Is there anything like Virtual Class present ?
Not by that name. What does it mean?
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
October 8th, 2008, 04:21 AM
#3
Re: Is there anything like Virtual Class present ?
Yes, by with different name.
-
October 8th, 2008, 04:30 AM
#4
Re: Is there anything like Virtual Class present ?
What is it ?
Is it mean by inheriting a base class as Virtual one ?
-
October 8th, 2008, 04:50 AM
#5
Re: Is there anything like Virtual Class present ?
If Virtual class is something like an abstract base class then there´s an equivalent in C++. Unlike as in java you don´t have to mark the abstract base class, all you have to do is to declare a pure virtual function and the class is automatically abstract.
Code:
/*no keyword needed here*/ class AbstractBaseClass
{
public:
AbstractBaseClass();
virtual ~AbstractBaseClass();
// pure virtual function declaration makes this class virtual/abstract
virtual func() = 0;
};
class ConcreteClass : public AbstractBaseClass
{
public:
ConcreateClass();
// implementation of inherited pure virtual function
void func();
};
Last edited by GNiewerth; October 8th, 2008 at 04:53 AM.
- Guido
-
October 8th, 2008, 11:17 AM
#6
Re: Is there anything like Virtual Class present ?
Originally Posted by rsodimbakam
What is it ?
Is it mean by inheriting a base class as Virtual one ?
I guess you could call a class virtual if it contains virtual functions. If all functions are pure virtual you could call the class abstract or an interface.
Then there's something called virtual inheritance. It's a way do avoid problems with multiple copies of the same class in a multiple inheritance situation. A class can be declared to be virtually inherited by the inheriting class.
Last edited by _uj; October 8th, 2008 at 11:33 AM.
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
|