jeudi 23 mai 2019

How to call the Appropriate constructor

Why I am not able to call the Appropriate Constructor for the Geometry object.

I have a Geometry Class.

class Geometry
  {
    private:
          float fRadius;
          int iSegments;
          float fWidth;
          float fLenght;
          std::string stdstrType;
          bool bValid;
      public:

      Geometry()
       {
          // Set data Elements
         qDebug() << "Constructor 1 is called";
       }

     Geometry(float Radius, int Segments , float Width , float Length , 
    std::string strType , bool bValue )
    {
      // Set data Elements
      qDebug() << "Constructor 2 is called";
    }

     Geometry(const Geometry &g)
    {
      // Set data Elements
      qDebug() << "Constructor 3 is called";
    }
 }

I use this class as a data variable in another class.

class Container
{
 private:
     std::string stdstrContainerName;
     std::string stdstrPluginType;
     Geometry Geom;

     public:
       Container();
       Container(std::string, std::string,  Geometry geometry );
};

Container::Container()
{
  stdstrContainerName = "Group";
  stdstrPluginType = "Geometry";
}

  Container::Container( std::string strName, std::string strType, 
  Geometry 
  geometry)
  {
    stdstrContainerName = stdstrContainerName;
    stdstrPluginType = stdstrPluginType;
    Geom = geometry;
   }

When I try to set a geometry object in the container 

geometry(0.3, 32, 0.0, 0.0, "SPHERE" , true);   
Container cont("Sphere" , "SPHERE" , geometry );

Though I have given all the parameters for the constructor number 2 to be called, the Geometry calls Constructor 1.

Aucun commentaire:

Enregistrer un commentaire