0

What does the "&" and "self" mean? when is it part of a function declaration?

I am not familiar with that syntax.

I could not get what it does after "&"

or when using self. xxxx. because without self this should work

Example:

example.c

classname::functionName(classname & self)
{
  self.m_state.mode.IsOnline = true;
}

example.h

static functionName(classname  & self);

class classname & _classname ;
{
    struct _MODE
    {
        bool IsOnline;
    } MODE;
} m_state;

This is c++

Regards

Ale
  • 23
  • 7
  • 3
    If you're unfamiliar with any C++ syntax, you should consider reading some tutorials and books about the language. – ForceBru Apr 02 '18 at 19:48
  • It means that there is a function named `function`, it is a member of the thing called `Class` (which is probably a class or a struct), and it takes a single argument. The argument is to be called `self` within this function (although it could just as well be called `sailboat`). It is of type `Class`, and the ampersand ('&') means that it is a reference variable, or to say it another way, the argument is passed by reference. If you want to know what "reference" means, you should consult a tutorial. – Beta Apr 02 '18 at 19:50
  • Your *example.h* is incorrect. – Robert Andrzejuk Apr 03 '18 at 07:16
  • why example.h is incorrect? a mate made that code and is working but I cant get how it works :s – Ale Apr 04 '18 at 00:54

0 Answers0