2 Replies - 201 Views - Last Post: 11 February 2014 - 12:12 PM Rate Topic: -----

#1 knils  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 50
  • Joined: 20-June 13

the this pointer return type problem

Posted 11 February 2014 - 10:38 AM

//empty& operator=(const empty& rhs)
//empty operator=(const empty& rhs)

whaever forward declaration i use from above the compiler does not show error for return *this, please someone explain this,regards

#include<iostream>
class empty
{
 int i;
 public:
 empty(int x):i(x){}

 empty& operator=(const empty& rhs)
 {
  i = rhs.i;
  return *this;
 }
 void fun()
 {
  std::cout<<i<<"\n";
 }
};


int main()
{
 empty e(10); //copy
 empty e1(e); //copy
 empty e2=e; //copy
 empty e3(20);
 e3=e;// assignment
 e.fun();
 e1.fun();
 e2.fun();
 e3.fun();
 return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: the this pointer return type problem

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3161
  • View blog
  • Posts: 9,541
  • Joined: 05-May 12

Re: the this pointer return type problem

Posted 11 February 2014 - 10:54 AM

Explain to us why you expecting to see an error. It'll be easier for us to understand what your mental picture is so that we can get in sync and have a better explanation.
Was This Post Helpful? 1
  • +
  • -

#3 knils  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 50
  • Joined: 20-June 13

Re: the this pointer return type problem

Posted 11 February 2014 - 12:12 PM

Sorry, I get the answer!!
It was return by value or reference I confused it with address.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1