How to deal with constructor argument names?
Posted
by
Bane
on Stack Overflow
See other posts from Stack Overflow
or by Bane
Published on 2012-10-10T15:27:09Z
Indexed on
2012/10/10
15:37 UTC
Read the original article
Hit count: 236
Say I have a class that has some properties, like x
, y
, width
and height
. In its constructor, I couldn't do this:
class A
{
public:
A(int, int, int, int);
int x;
int y;
int width;
int height;
};
//Wrong and makes little sense name-wise:
A::A(int x, int y, int width, int height)
{
x = x;
y = y;
width = width;
height = height;
}
First of all, this doesn't really make sense. Second, x
, y
, width
and height
become some weird values (-1405737648) when compiled using g++. It does work, however, if I append "a" to the argument names.
What is the optimal way of solving these naming conflicts?
© Stack Overflow or respective owner