Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

this pointer question

Status
Not open for further replies.

Lucifre

Full Member level 2
Full Member level 2
Joined
Jul 5, 2005
Messages
125
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,296
Location
Detroit MI
Activity points
2,389
What does
Code:
return *this;
mean? code sniplets to explain would be apreciated
 

"this" pointer will point to the currently referring class object. So "*this" will be the data value of the class object. Hence
Code:
.............
..............

Class1 Class1::func1() {
    return *this;
}

................
................
Class1 var1, var2;
var2 = var1.func1();

will always set "var2" by the value of the class object with which the member function was called (var1).
This may be overrided by using an assignment operator (Class1::eek:perator=()). But if the return type was by refernce (ie: Class1& func1()) "Class1 &var2 = var1.func1();" will set var2 as a reference to var1. Also this may have a different behaviour if the return (by value) type was set to initialize a class object.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top