A simple class with member variable, constructor, destructor : Class Basics « Class « C++






A simple class with member variable, constructor, destructor

A simple class with member variable, constructor, destructor
#include <iostream>
using namespace std;

class who {
  char name;
public:
  who(char c) { 
     name = c;
     cout << "Constructing who";
     cout << name << endl;
  }
  ~who() { 
     cout << "Destructing who: " << name << endl; 
  }
};

who makewho()
{
  who temp('B');
  return temp;
}

int main()
{
  who ob('A');

  makewho();

  return 0;
}


           
       








Related examples in the same category

1.Class forward declarationClass forward declaration
2.Simplest class definitionSimplest class definition
3.Address class: class definition and implementationAddress class: class definition and implementation
4.Declare class instanceDeclare class instance
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