How to declare a function parameter does this?

f(this) //<- what to do?

Some class
{
public:
Some()
{
f(this);
}
};

f(C this){ ... }
July 2nd 19 at 17:29
1 answer
July 2nd 19 at 17:31
Solution
this is a pointer, respectively, the function should take a pointer:

void foo(Some *ptr);
foo(this);


But this is not necessary, because the pointer can be dereferenced using operator *, for example:

void foo(Some a); //function
foo(*this); //function call
About the pointer know. The essence of the question. If I declare the function before the class, the function can not accept it as it does not see class, if it determines after, you can't use in the constructor. - felicita_Homenick commented on July 2nd 19 at 17:34
: You can write a class Declaration before the function.

class Some;

void foo(Some a); //function for example

class Some {
//class definition
}; - Jeremy_Bartoletti commented on July 2nd 19 at 17:37
: I Sarabia thanks - felicita_Homenick commented on July 2nd 19 at 17:40
and how about to mark the answer solution? :) - Benjamin_McClure commented on July 2nd 19 at 17:43
:
:)) - Jeremy_Bartoletti commented on July 2nd 19 at 17:46

Find more questions by tags C++