Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In C++, what is the difference between a method and a function [duplicate]

Possible Duplicate:
What is the difference between a method and a function

I'm trying to get my terminology correct.

What is the difference between a method and a function, in regards to C++ specifically.

Is it that a method returns nothing and just preforms operations on its class; while a function has a return value?

like image 665
Wes Avatar asked Dec 21 '11 21:12

Wes


People also ask

Whats the difference between a function and a method?

Method and a function are the same, with different terms. A method is a procedure or function in object-oriented programming. A function is a group of reusable code which can be called anywhere in your program. This eliminates the need for writing the same code again and again.

What is the difference between a method and a function C#?

Methods and Functions are the same in C#. However, Methods are used in C# and are functions that operate through a designated class. A method is a group of statements that together perform a task. Every C# program has at least one class with a method named Main.

Is method a function in C#?

A method is a block of code which only runs when it is called. You can pass data, known as parameters, into a method. Methods are used to perform certain actions, and they are also known as functions.

What is a method in CPP?

Methods are functions that belongs to the class. There are two ways to define functions that belongs to a class: Inside class definition. Outside class definition.


2 Answers

As far as the C++ standard is concerned, there is no such thing as a "method". This terminology is used in other OO languages (e.g. Java) to refer to member functions of a class.

In common usage, you'll find that most people will use "method" and "function" more or less interchangeably, although some people will restrict use of "method" to member functions (as opposed to "free functions" which aren't members of a class).

like image 113
Oliver Charlesworth Avatar answered Oct 15 '22 14:10

Oliver Charlesworth


Sorry, but this is one of my pet peeves. Method is just a generic OO-type term. Methods do not exist in C++. If you open the C++ standard, you won't find any mention of "methods". C++ has functions, of various flavors.

like image 26
Brian Neal Avatar answered Oct 15 '22 15:10

Brian Neal