C++ ClassesLesson 33Free preview
C++ Class Methods
This lesson is part of C++ · All levels
Summary
A method is a function that lives within a class and performs a task related to that object's data. Method can be written directly within a class or declared in a class and then defined outside a class with the operator: With methods, data and object behavior combined neatly, making the program easier to handle.
Key points
- Method is declared in class and called using the dot (.) or arrow (->) mark on object or pointer.
- The definition of a method outside the class is written as void NameClass::namaMethod() {...}.
- Method can be given a modifier const if it does not change the data member, so it is safe to call on the object const.
- The static method belongs to the class and can be called without creating an object.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.