| | |
Why constructor can not be defined as virtual
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
google is a wonderful invention 
http://www.codersource.net/published...ctions_in.aspx

•
•
•
•
A constructor cannot be virtual because at the time when the constructor is invoked the virtual table would not be available in the memory. Hence we cannot have a virtual constructor.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
I think the only way to create a "virtual constructor" is to make a virtual method that returns the object inquestion, where derived classes return a copy of their type instead of the base classes return implementation.
By casting a derived type to a base type and invoking the virtual constructor method, you're constructing an object virtually, therefore it's safe to say it is a "virtual constructor".
By casting a derived type to a base type and invoking the virtual constructor method, you're constructing an object virtually, therefore it's safe to say it is a "virtual constructor".
![]() |
Similar Threads
- C++ Performance Tips (C++)
- Modified Copy Constructor Difficulty (C++)
- default constructor&class (C++)
- Class Vectorization requirements (C++)
- C++ tips (C++)
- unresolved external error upgrading 6.0-7.1 (C++)
- accessing private data members (C++)
Other Threads in the C++ Forum
- Previous Thread: problem reading a in reverse order
- Next Thread: writing to a file
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






