By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,442 Members | 1,437 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,442 IT Pros & Developers. It's quick & easy.

Virtual Class - why?

P: n/a
Hi

What is the purpose of declaring a class with a "Virtual" in front?
What is the benefit?

Thanks

Dec 19 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
2005 wrote:
Hi

What is the purpose of declaring a class with a "Virtual" in front?
None.
What is the benefit?
The only effect is that the program won't compile, but I'd not count that as
benefit.

Dec 19 '06 #2

P: n/a

Rolf Magnus wrote:
2005 wrote:
Hi

What is the purpose of declaring a class with a "Virtual" in front?

None.
What is the benefit?

The only effect is that the program won't compile, but I'd not count that as
benefit.
I have it in the notes

"virtual class xxxx" (ignoring the case sensitiveness if there is
any).

Can someone clarify pls?

Dec 19 '06 #3

P: n/a
2005 wrote:
What is the purpose of declaring a class with a "Virtual" in front?

None.
What is the benefit?

The only effect is that the program won't compile, but I'd not count that
as benefit.

I have it in the notes

"virtual class xxxx" (ignoring the case sensitiveness if there is
any).
C++ is indeed case sensitive. The virtual keyword (as all C++ keywords)
would be written in all lowercase letters.
Can someone clarify pls?
Maybe you're talking about some other language. In standard C++, this simply
makes no sense.
Dec 19 '06 #4

P: n/a
2005 wrote:
[SNIP]
"virtual class xxxx" (ignoring the case sensitiveness if there is
any).
Wasn't that "virtual *base* class" ?
--
WW aka Attila
:::
Drag me, drop me, treat me like an object!
Dec 19 '06 #5

P: n/a

2005 wrote:
Rolf Magnus wrote:
2005 wrote:
Hi
>
What is the purpose of declaring a class with a "Virtual" in front?
None.
What is the benefit?
The only effect is that the program won't compile, but I'd not count that as
benefit.

I have it in the notes

"virtual class xxxx" (ignoring the case sensitiveness if there is
any).
Everything in C++ is case sensitive except for your comments.
The only time a virtual class is met in C++ is in virtual inheritance.
[25.8] What is the "dreaded diamond"?
http://www.parashift.com/c++-faq-lit...heritance.html

Dec 19 '06 #6

P: n/a
A virtual class would be a key in solving the diamond problem with multiple
inheritance, see
http://en.wikipedia.org/wiki/Diamond_problem

Hope this helps

Moon2
Dec 21 '06 #7

P: n/a
Moon2 wrote:
A virtual class would be a key in solving the diamond problem with multiple
inheritance, see
http://en.wikipedia.org/wiki/Diamond_problem
Virtual inheritance (there's no such thing as a virtual class, but we
all know what's meant by that term) MIGHT be a way to approach solving
such a problem if the problem arose because of a design error.
Unfortunately, there's a great deal of folklore about the "dreaded
diamond", etc. that's based on the assumption that deriving from the
same base through multiple paths must be an error. It's not necessarily so.

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
Dec 21 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.