This topic is now archived and is closed to further replies.


returning an object vie a this pointer.

Recommended Posts

lets say i have a class called Employee. and another class called Person. now lets say that the Employee class looks something like this, roughly, for simplicity''s sake.
class Employee {
   void SetPersonInfo( Person &person)
      m_person = person;

   Person *m_person;
this doesnt work for some odd reason. i believe i need to explicity define a copy constructor or the = operator. the error i receive is
: error C2679: binary ''='' : no operator defined which takes a right-hand operand of type ''class CGDPGraph'' (or there is no acceptable conversion)
im just confused when i need to define a copy constructor and when i need to define an = operator. could someone shed some light please?

Share this post

Link to post
Share on other sites
You''re trying to assign an actual Person object (passed in by reference) to a Person pointer. It is confusing that & is both used to indicate pass by reference and the address of an element.

Depending on the Person class, I''d probably just make m_person an object, not a pointer. It''s safer. In that case also make it SetPersonInfo(const Person &person).

Share this post

Link to post
Share on other sites
Sure it can, but a pointer stores an address, not an object. You need to give that pointer the address of person.

m_person = &person;

I didn''t think you wanted that because it strikes me as a bit odd (but I obviously have little context to go on).

Share this post

Link to post
Share on other sites