Is this ambiguous or is it perfectly fine?
c++, coding-style, constructor, initialization, standards
Solution
No, in this case there are no ambiguity, but consider following:
struct SCustomData {
//...
void SetCode(int nCode)
{
//OOPS!!! Here we do nothing!
//nCode = nCode;
//This works but still error prone
this->nCode = nCode;
}
};
You should draw attention to one of existing coding styles. For instance General Naming Rule in Google C++ Coding Styles or read excellent book "C++ Coding Standards: 101 Rules, Guidelines, and Best Practices" by Herb Sutter and Andrei Alexandrescu.
Problem
Is this code ambiguous or is it perfectly fine (approved by standards/has consistent behavior for any compilers in existence)? ``` struct SCustomData { int nCode; int nSum; int nIndex; SCustomData(int nCode, int nSum, int nIndex) : nCode(nCode) , nSum(nSum) , nIndex(nIndex) {} }; ``` edit: yes, I am referring to the fact that the member variables have the same name with formal parameters of the constructor.