0

What does Test& Test::func () mean?

I have been learning 'this' pointer. And everywhere I see is this format of calling class and accessing the member function and constructor. What does it mean?

11th Jun 2020, 1:02 AM
Prashant Pant
Prashant Pant - avatar
4 ответов
+ 2
Prashant Pant This may help to introduce what a reference type is ... https://en.m.wikipedia.org/wiki/Reference_(C%2B%2B) https://www.geeksforgeeks.org/references-in-c/ Anyways, I think the first return statement should be `return s;` rather than `return x;`. Variable <x> is an unknown there : )
11th Jun 2020, 8:26 AM
Ipang
+ 2
Is that all there is? maybe a complete block of the code can improve clarity. As I see it, it is a definition of a member function named `func`. The fuction is a member of a class named `Test`, and it returns a reference to an object instantiated from the `Test` class itself.
11th Jun 2020, 3:25 AM
Ipang
+ 1
Ipang What does "it returns a reference to an object" mean?
11th Jun 2020, 5:33 AM
Prashant Pant
Prashant Pant - avatar
+ 1
Ipang here is the code snippet. class person { char name[20]; float age; public: person(char *s, float a) { strcpy(name, s); age=a; } person & person::greater(person &s) //returns a reference to an object. what does it mean? { if(s.age>=age) return x; else return *this; }
11th Jun 2020, 5:37 AM
Prashant Pant
Prashant Pant - avatar