Simplest class definition : Class Basics « Class « C++






Simplest class definition

Simplest class definition

#include <iostream>
using namespace std;

class SimpleClass {
  int len;
public:
  SimpleClass(int l);
};

SimpleClass::SimpleClass(int l)
{
  len = l;

  int i;
  for(i = 0; i <len; i++) 
     cout  << '*';
}

int main()
{
  SimpleClass l(10);

  return 0;
}

           
       








Related examples in the same category

1.Class forward declarationClass forward declaration
2.A simple class with member variable, constructor, destructorA simple class with member variable, constructor, destructor
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