C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 27)
27.
Which of the following cannot be used with the keyword virtual?
class
member functions
constructor
destructor
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
20 comments Page 2 of 2.

Rajendra said:   1 decade ago
Can we declare virtual class?

Pooja Singh said:   1 decade ago
Yes, we can declare class as a virtual. It removes ambiguity of same function name used in different classes.

Example - hybrid inheritance.

Prosenjit Santra said:   1 decade ago
I think we cannot create virtual constructor as well as virtual destructor.

Sumit said:   1 decade ago
You are thinking well. But, we can create virtual destructor.

Prakash kuthi said:   9 years ago
Hi, it was helpful thanks to all.

Gelu Menumorut said:   9 years ago
There is no such a thing as a "virtual class", but only the expression "virtual base class" that is just an euphemism that has sense only in the context of inheritance, meaning the base class involved in virtual inheritance, here the word "virtual" is actually an attribute of the inheritance not of the class. Is like "C++ slang", but altering the expression and it's context and making it official by saying it's a correct answer is weird, to say the least.
(1)

Pankaj said:   9 years ago
Constructors can be virtual and static. So right answer is destructor D option.

Nitin said:   8 years ago
The virtual not work with destructor.

Rabz said:   5 years ago
Constructor cannot be virtual because the time when constructor is called, there is no virtual table in the memory yet. But destructor can be virtual.
(2)

Arnab Pratihar said:   4 weeks ago
The "virtual" keyword is used to prevent early binding which checks which function is called at runtime, known as "late binding".

But the constructor is called at runtime, that's why no late binding problem occurs with the constructor. That is the actual reason virtual keyword is not used or can't be used before the constructor.


Post your comments here:

Your comments will be displayed after verification.