D
Divick
Hi,
I have the following code (see below). My compiler g++ 3.4.6 doesn't
compile it. I wonder why shouldn't this be allowed? I understand that
const int a, would be different for different objects, unlike static
const. And functions are common for all objects. But from the
compiler's perspective, shouldn't it be simple to handle as for every
invocation of a function with default argument, if the value is not
supplied then the compiler can simply initialize the function with the
value on which the function has been called?
class x
{
private :
const int a;
public :
X() : a(1)
{}
void foo(int arg = a)
{
cout << arg << endl;
}
};
Thanks in advance,
-DK
I have the following code (see below). My compiler g++ 3.4.6 doesn't
compile it. I wonder why shouldn't this be allowed? I understand that
const int a, would be different for different objects, unlike static
const. And functions are common for all objects. But from the
compiler's perspective, shouldn't it be simple to handle as for every
invocation of a function with default argument, if the value is not
supplied then the compiler can simply initialize the function with the
value on which the function has been called?
class x
{
private :
const int a;
public :
X() : a(1)
{}
void foo(int arg = a)
{
cout << arg << endl;
}
};
Thanks in advance,
-DK