What is the meaning of const in this case???
Hello, Could anyone explain const for me in this case. this's a code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
class Employee
{
public:
Employee(const string &,const string &);
void setFirstName(const string &);
string getFirstName()const;
void setLastName(const string &);
string getLastName()const;
private:
string firstname,lastname;
};
Employee::Employee(const string &first,const string &last)
:firstname(first),lastname(last)
{
}
int main()
{
SalariedEmployee salariedEmp("John","Smith");
return 0;
}
|
my problem is what different when I put const in different position? like these two functions?
1 2
|
void setFirstName(const string &);
string getFirstName()const;
|
void setFirstName(const string&);
const here means that the function is not allowed to manipulate the string being passed to the function.
string getFirstName() const;
const here means that the function is not allowed to manipulate the object itself (its member variables).
Thank you Peter87
Topic archived. No new replies allowed.