Declare class instance : Class Basics « Class « C++






Declare class instance

Declare class instance
#include <iostream>
using namespace std;

class myclass {
  int a;
public:
  myclass(int x) { 
     a = x; 
  } 
  int geta() { 
     return a; 
  }
};
 
int main()
{
  myclass ob(4);

  cout << ob.geta();

  return 0;
}



           
       








Related examples in the same category

1.Class forward declarationClass forward declaration
2.Simplest class definitionSimplest class definition
3.A simple class with member variable, constructor, destructorA simple class with member variable, constructor, destructor
4.Address class: class definition and implementationAddress class: class definition and implementation
5.Constructor: different parameter typeConstructor: different parameter type
6.Declare Class instance and use themDeclare Class instance and use them
7.Assign object1 to object2Assign object1 to object2
8.Init Object arrayInit Object array