i have a c++ project and am using has-a inheritance ... the project is to create a class Sensor then makes is-a inheritance to classes Regular Sensor and CriticalSensor .. uptill now no problem ... i want then to create a class Building that (has) sensors so am using has-a inheritance ... the problem is that i dont know how to make the constructos and destructors of the class Building ... any fast help is appreciated
10x n advance :-)

well:

class Sensor{
        Sensor();
        Sensor (int ,doubel , ....) 
};
class RegularSensor:public Sensor{........};
class CriticalSensor:public Sensor{......};

uptill this point all is done

class Building{
     RegularSensor rs;
     CriticalSensor cs;
      int x; // for example
public:
      Building();
      Building(int,const RegularSensor &, const CriticalSensor &);
     ~Building();
....
};

how can i create the the constructors and destructors of building ? :-) i should call the constructors of the RegularSensor and CriticalSensor ... but how can i do this ??

Edited 3 Years Ago by mike_2000_17: Fixed formatting

As usually, via ctor-initializers list:

Building::Building(int i, 
    const RegularSensor & r,
    const CriticalSensor & c)
    : x(i), rs(r), cs(c) // that's it: learn C++ more carefully;)
{
   ...
}

10x :) i already did this but when i go:
Building* ptr;
ptr=new Building;
am getting a thread ... i thought something wrong with the constructor ... it is a ptr issue maybe .. i tried everything and did not work ... for example i tried to assign NULL to the pointers and it is the same ...
anyway 10x a lot 4 ur time

This article has been dead for over six months. Start a new discussion instead.