c++ - Calling base class constructor on init in GCC vs MSVC2010 -


i cross-compiling project msvc2010 gcc 4.7 .each place call base class constructor :

 fpscamera::fpscamera(cameratype camtype, float fov, int viewportw, int viewporth, float nearplane, float farplane) {     camera3d::camera3d( camtype,  fov,  viewportw,  viewporth,  nearplane,  farplane);  } 

i getting in gcc :

cannot call constructor directly

msvc doesn't complain ... way error fixed:

fpscamera::fpscamera(cameratype camtype, float fov, int viewportw, int viewporth, float nearplane, float farplane)         :camera3d( camtype,  fov,  viewportw,  viewporth,  nearplane,  farplane);  {  } 

why?

this bug in vc++ 2010 - constructors nameless special member functions , cannot called directly. in case default constructor of base class called fist then parameterized constructor of base class called. reason may not have noticed problems this pointer different between both calls base constructors. 2 separate objects appear getting constructed 1 being destroyed. depending on resources acquired base class there may leaks or bugs not aware of yet.

the example below shows happening during construction.

#include <iostream>  class base { public:     base()     {         std::cout << "base default ctor. = " << << std::endl;     }     base(int)     {         std::cout << "base parameterized ctor. = " << << std::endl;     } };  class derived : public base { public:     derived()     {         std::cout << "inside derived ctor." << std::endl;         base::base(1);         std::cout << "leaving derived ctor" << std::endl;     } };    int main() {     derived();     return 0; } 

results:

base default ctor. = 00000000002ff6f0
inside derived ctor.
base parameterized ctor. = 00000000002ff6b0
leaving derived ctor

[note: microsoft has no plans of fixing problem time soon]


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -