fork download
  1. #include <iostream>
  2.  
  3. class Geometry {
  4. private:
  5. float fRadius;
  6. int iSegments;
  7. float fWidth;
  8. float fLenght;
  9. std::string stdstrType;
  10. bool bValid;
  11.  
  12. public:
  13. Geometry() {
  14. // Set data Elements
  15. std::cout << "Constructor 1 is called\n";
  16. }
  17.  
  18. Geometry(float Radius, int Segments, float Width, float Length,
  19. std::string strType, bool bValue) {
  20. // Set data Elements
  21. std::cout << "Constructor 2 is called\n";
  22. }
  23.  
  24. Geometry(const Geometry & g) {
  25. // Set data Elements
  26. std::cout << "Constructor 3 is called\n";
  27. }
  28. };
  29.  
  30. class Container {
  31. private:
  32. std::string stdstrContainerName;
  33. std::string stdstrPluginType;
  34. Geometry Geom;
  35.  
  36. public:
  37. Container(std::string, std::string, Geometry geometry);
  38. };
  39.  
  40. Container::Container(std::string strName, std::string strType,
  41. Geometry geometry) {
  42. stdstrContainerName = stdstrContainerName;
  43. stdstrPluginType = stdstrPluginType;
  44. Geom = geometry;
  45. }
  46.  
  47. class ContainerWithMemberInit {
  48. private:
  49. std::string stdstrContainerName;
  50. std::string stdstrPluginType;
  51. Geometry Geom;
  52.  
  53. public:
  54. ContainerWithMemberInit(std::string, std::string, Geometry geometry);
  55. };
  56.  
  57. ContainerWithMemberInit::ContainerWithMemberInit(std::string strName, std::string strType, Geometry geometry)
  58. : stdstrContainerName(strName)
  59. , stdstrPluginType(strType)
  60. , Geom(geometry) // copy-constructor, i.e. Geometry(Geometry const&)
  61. {
  62. }
  63.  
  64. int main() {
  65. {
  66. Geometry geometry(0.3, 32, 0.0, 0.0, "SPHERE", true);
  67. // Constructor 2 is called
  68. Container cont("Sphere", "SPHERE", geometry);
  69. // Constructor 3 is called
  70. // Constructor 1 is called
  71. }
  72. std::cout << "break\n";
  73. {
  74. Geometry geometry(0.3, 32, 0.0, 0.0, "SPHERE", true);
  75. // Constructor 2 is called
  76. ContainerWithMemberInit cont("Sphere", "SPHERE", geometry);
  77. // Constructor 3 is called
  78. // Constructor 3 is called
  79. }
  80. }
  81.  
  82.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Constructor 2 is called
Constructor 3 is called
Constructor 1 is called
break
Constructor 2 is called
Constructor 3 is called
Constructor 3 is called