public fields and member functions : public « Class « C++ Tutorial






#include <iostream>
using namespace std;

class MyClass {

public:
  int number;
  void display(); 
};

void MyClass::display()
{
  for(int i = 0; i<= number;i++)
  {
     cout<< "Hello World \n";
  }
  
}
int main () 
{
       MyClass myfirstobject;

       myfirstobject.number =3; 
    myfirstobject.display();


       return 0;
}
Hello World
Hello World
Hello World
Hello World








9.11.public
9.11.1.public fields and member functions
9.11.2.Initialize the public data members in a class