Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

(C++) Method

 

A class's member function.

 

Const methods do not change the (non-mutable) member variables.

 

Follow a standard method design.

 

Trivial example

 

 

struct HelloWorld

{

void SayHelloWorld() const { std::cout << "Hello World" << std::endl; }

};

 

 

int main()

{

HelloWorld h;

h.SayHelloWorld();

}

 

The class 'HelloWorld' has a single const method called 'SayHelloWorld'. It is called in main, producing the same output as a Hello World program.

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.