Jump to content
  • Advertisement

Archived

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

GekkoCube

returning an object vie a this pointer.

This topic is 5434 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 {
 public:
   void SetPersonInfo( Person &person)
   {
      m_person = person;
   }

 private:
   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
Advertisement
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
oh gee, i meant m_person = &person.

i am ultimately going to use m_person within th Employee class...something liek this...


person->GetName();
person->GetAge();


you get the picture.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!