Hi, this is my first post and I need your help, I need examples of how to use methods in c, that are simple, for example do any math operation with the variables that are part of the class. And, if you can, compare the method of the class with a normal function of structure. Please help me.

A simple class

class MyClass
{
public:
   MyClass()
   {
      x = 0;
   }
   int Add(int n)
   {
      this->x += n;
   }
private:
   int x;
};

A normal function outside a class might look like this:

struct MyStruct
{
   int x;
};

int sum(int n, struct MyStruct* s)
{
    s->x += n;
    return s->x;
}

In c and c++ they are refered to as functions. Methods are used in C#, java, etc...

>>In c and c++ they are refered to as functions.

I refer to functions inside c++ classes (member functions) as methods. Functions not in a c++ class are referred to as just a function. But maybe the terminology has changed a little since I went to school.

Oh, I guess if im working in c++, I just call everything a function, but I believe you are technically right =p.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.