Member Function versus Non-Member Function (2024)

A non-member function always appears outside of a class.

The member function can appear outside of the class body (for instance,in the implementation file). But, when you do this, the member function must be qualified by the name of its class.This is to identify that that function is a member of a particular class.

For instance, if you took our myarray class and wanted to define the implementation of a new member function called myfunction outside the body of the class.

You would write:

int myarray::myfunction(int a, int b){...//details of this implementation //note: you need the protype of myfunction in the body of myarray}
The myarray:: specifies that the myfunction belongs to the myarray class.

By contrast, a non-member function has no need to be qualified. It does notbelong to a class. In the implementation file, I could write my non-member function as:

int myfunction (int a, int b){..//details of this implementation}
Member Function versus Non-Member Function (2024)
Top Articles
Latest Posts
Article information

Author: Barbera Armstrong

Last Updated:

Views: 6423

Rating: 4.9 / 5 (79 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Barbera Armstrong

Birthday: 1992-09-12

Address: Suite 993 99852 Daugherty Causeway, Ritchiehaven, VT 49630

Phone: +5026838435397

Job: National Engineer

Hobby: Listening to music, Board games, Photography, Ice skating, LARPing, Kite flying, Rugby

Introduction: My name is Barbera Armstrong, I am a lovely, delightful, cooperative, funny, enchanting, vivacious, tender person who loves writing and wants to share my knowledge and understanding with you.