-
July 1st, 2008, 01:59 PM
#1
[RESOLVED] What does a & after an argument/variable type signify?
I've run across this code and have seen similar code before, but I'm not sure what it means
Code:
//--- file Person.h
. . .
class Person {
private:
char* _name;
int _id;
public:
Person& Person::operator=(const Person& p);
. . .
}
//--- file Person.cpp
. . .
//=================================================== operator=
Person& Person::operator=(const Person& p) {
if (this != &p) { // make sure not same object
delete [] _name; // Delete old name's memory.
_name = new char[strlen(p._name)+1]; // Get new space
strcpy(_name, p._name); // Copy new name
_id = p._id; // Copy id
}
return *this; // Return ref for multiple assignment
}//end operator=
Why is there a & after Person? What is it saying to the compiler?
-
July 1st, 2008, 02:02 PM
#2
Re: What does a & after an argument/variable type signify?
Originally Posted by Brownhead
Why is there a & after Person? What is it saying to the compiler?
That is the reference operator. The return value is a reference to a Person object, and the argument passed is a reference to a Person.
References, pointers, etc. should be discussed in any elementary C++ book.
Regards,
Paul McKenzie
-
July 1st, 2008, 02:33 PM
#3
Re: What does a & after an argument/variable type signify?
Thank you , I never learned about references.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|