useer degined Copy ctor, and copy-ctors further down the chain - compiler bug ? programers brainbug

Posted by J.Colmsee on Stack Overflow See other posts from Stack Overflow or by J.Colmsee
Published on 2010-03-08T07:52:49Z Indexed on 2010/03/08 8:06 UTC
Read the original article Hit count: 197

Filed under:
|
|

Hi. i have a little problem, and I am not sure if it's a compiler bug, or stupidity on my side. I have this struct :

struct BulletFXData
{
 int time_next_fx_counter;
 int next_fx_steps;
 Particle particles[2];//this is the interesting one
 ParticleManager::ParticleId particle_id[2];
};

The member "Particle particles[2]" has a self-made kind of smart-ptr in it (resource-counted texture-class). this smart-pointer has a default constructor, that initializes to the ptr to 0 (but that is not important)

I also have another struct, containing the BulletFXData struct :

struct BulletFX
{
 BulletFXData     data;
 BulletFXRenderFunPtr   render_fun_ptr;
 BulletFXUpdateFunPtr   update_fun_ptr;
 BulletFXExplosionFunPtr  explode_fun_ptr;
 BulletFXLifetimeOverFunPtr  lifetime_over_fun_ptr;

 BulletFX( BulletFXData     data,
    BulletFXRenderFunPtr   render_fun_ptr,
    BulletFXUpdateFunPtr   update_fun_ptr,
    BulletFXExplosionFunPtr  explode_fun_ptr,
    BulletFXLifetimeOverFunPtr  lifetime_over_fun_ptr)
 :data(data),
 render_fun_ptr(render_fun_ptr),
 update_fun_ptr(update_fun_ptr),
 explode_fun_ptr(explode_fun_ptr),
 lifetime_over_fun_ptr(lifetime_over_fun_ptr)
 {
 }
/*
 //USER DEFINED copy-ctor. if it's defined things go crazy
     BulletFX(const BulletFX& rhs)
     :data(data),//this line of code seems to do a plain memory-copy without calling the right ctors
     render_fun_ptr(render_fun_ptr),
     update_fun_ptr(update_fun_ptr),
     explode_fun_ptr(explode_fun_ptr),
     lifetime_over_fun_ptr(lifetime_over_fun_ptr)
     {
     }
    */
    };

If i use the user-defined copy-ctor my smart-pointer class goes crazy, and it seems that calling the CopyCtor / assignment operator aren't called as they should. So - does this all make sense ? it seems as if my own copy-ctor of struct BulletFX should do exactly what the compiler-generated would, but it seems to forget to call the right constructors down the chain. compiler bug ? me being stupid ?

Sorry about the big code, some small example could have illustrated too. but often you guys ask for the real code, so well - here it is :D

© Stack Overflow or respective owner

Related posts about c++

Related posts about compiler