Reputation: 321
I am using pass by reference to const string in a function argument like below:
class Super
{
void alignment(const string & str);
};
void Super::alignment(const string & str)
{
//do some stuff
}
Now if I use as below it gives the same result:
void Super::alignment(string const & str)
{
//do some stuff
}
What is the difference in this two types of definition in c++?
Upvotes: 1
Views: 1011
Reputation: 641
the const keyword is left associative, but in "const string &str", since there's no left keyword to qualify, it apply to the word at his right (so string).
It is the same but it's not parsed the same.
Upvotes: 4
Reputation: 76240
const T&
and T const&
are semantically the same exact thing. Just like const T*
and T const*
are semantically the same, but T const*
and T* const
are different.
Upvotes: 7