A function fits in the style of procedural programming. A piece of code programmed that way is a collection of data, that can be accessed by any function, and functions that can operato on that data. (I am simplifying a bit here)
A function has a name, and a signature. The signature is defined by the return value and the parameters that are being passed.
To call a function in a program, one simply uses the function name.
void foo(){
printf("foo\n");
}
void main(){
foo();
}
A method fits in the style of object oriented programming.The idea is to define classes, where classes are a collection of data together with the functions (that are called methods now) that operate on that data. This is called encapsulation. The reason for doing this is, is to obtain a better maintainable program. By doing encapsulation the data dat belongs to a certain object can only be modified by the methods that have been provided by the class. An object is an instance of a class.
class myclass{
public:
int geta();
int getb();
int getMultiply();
myclass(int a,int b);
private:
int _a;
int _b;
}
myclass::myclass(int a,int b)
:_a(a),_b(b){}
int myclass::geta(){return _a;};
int myclass::getb(){return _b;};
int myclass::getMultiply(){return _a*_b;};
void main(){
myclass instance(5,6);
printf("multiply=%d\n",instance.getMultiply());
}
to call on a method, one has to provide the object on which the method is to operate, and the method name.
I am only scratching the surface here, the best way to find out about a method is to read the first chapters of a book about OO.