Function vs Method

The main difference between a function and a method is that a function can live independently of the any instance of a class, where as a method sits within a class.

That is about it, e.g. a function is

int func(int value);
...
 
int main()
{
  cout << funct(3) << endl;
}

whereas a method has to live within a class

class myclass
{
    int myMethod(int it);
};
 
....
 
int main()
{
   myclass theclass;
   cout << theclass.myMethod(4) << endl;
}

Leave a Reply

Your email address will not be published. Required fields are marked *