Advertisement

Constructor not being called.. help?

Started by November 13, 2000 02:13 PM
3 comments, last by A. Buza 24 years, 1 month ago
I have a class (CWindowedDisplay) that is derived from an abstract base class (CDisplay). However, when I create an instance of CWindowedDisplay (CDisplay *gfx; gfx= new CWindowedDisplay()), the constructor for CWindowedDisplay isn''t called. I''ve looked through the C++ documentation, and I couldn''t find anything that would solve my problem. Could somebody please give me a clue? Thanks!
That''s strange. How do you know that the base constructor is not called? Have you tried something like

  class base{        public:        base()        {   		//Write to a log or display message        }};class derived : public base{        public:        derived()        {		//Write to a log or display message         }};  


Then check you log file. If it still doesn''t work, post a snippet of the base and derived constructors.


--------------
Andrew
Advertisement
My guess is that it called the default constructor. If you want new CWindowedDisplay() to call your constructor then you have to define one taking no parameters or one with defaults for all the parameters. Remember you can overload functions so func(int) isn''t the same as func(void).
Keys to success: Ability, ambition and opportunity.
I think the constructor may need to be virtual in the base class for that code to work
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
There are no such thing as virtual constructors. But I think LilBudyWizer is right, make sure your constructor, CWindowedDisplay(), takes no arguments, or alternativly write CDisplay *gfx = new CWindowedDisplay(argument1, argument2, ...).

Edited by - fredizzimo on November 13, 2000 12:17:29 AM

This topic is closed to new replies.

Advertisement