Creates two objects. : instance object « Class « C++ Tutorial






#include <iostream> 
using namespace std; 
 
class ThreeDimension {  
public: 
  int X;
  int Y;   
  int Z;       
}; 
  
int main() {  
  ThreeDimension aDimension; 
  ThreeDimension bDimension; 
 
  int range1, range2;  
 
  aDimension.X = 7; 
  aDimension.Y = 16; 
  aDimension.Z = 21; 
  
  bDimension.X = 2; 
  bDimension.Y = 14; 
  bDimension.Z = 12; 

  range1 = aDimension.Y * aDimension.Z; 
  range2 = bDimension.Y * bDimension.Z; 
  
  cout << range1 << "\n";  
 
  cout << range2;  
  
  return 0; 
}
336
168








9.32.instance object
9.32.1.Using an empty initializer
9.32.2.Automatically converted into MyClass(4): MyClass ob = 4;
9.32.3.MyClass ob(4)
9.32.4.MyClass ob = MyClass(4);
9.32.5.Creates two objects.
9.32.6.Object assignment
9.32.7.Creating objects on the heap using new
9.32.8.Accessing members of objects on the heap
9.32.9.Call class constructor without new operator
9.32.10.Assign class object