In the following code, I have provided default arguments for array subscript operator.
struct st
{
int operator[](int x = 0)
{
// code here
}
};
But, compiler generated an error :
error: 'int st::operator[](int)' cannot have default arguments
int operator[](int x = 0)
But, If I provide default arguments for function call operator.
struct st
{
int operator()(int x = 0)
{
// code here
}
};
It's working fine.
So, I have a questions:
- Why doesn't allowed default arguments for the array subscript operator?
- Why does allowed default arguments for the function call operator?