Methods

Methods

C++ class methods are user-defined functions that can be used within an instance of the class. We use a dot notation . before method names to distinguish them from regular functions.

Class Methods

A class method can be defined in two ways:

  • Inside the class definition
  • Outside the class definition

Inside the Class

Loading...

Outside the Class

Loading...

Parameters can also be added to class methods:

Loading...
Edit this page on GitHub

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your feedback.

Learn C++ on Codecademy