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 1 of 2.

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)

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)

Sushil said:   1 decade ago
There is nothing like Virtual Constructor. The Constructor can't be virtual as the constructor is a code which is responsible for creating an instance of a class and it can't be delegated to any other object by virtual keyword means.
(1)

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

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.

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

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

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

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

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


Post your comments here:

Your comments will be displayed after verification.