0

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.

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by LevyDee
0

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;
}
0

>>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.

Edited by Ancient Dragon: n/a

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.