I want to assign a class a value on declaration so I made this basic class:
class A
{
public:
A &operator=(int)
{
return (*this);
}
};
and compiled it with this main:
int main(void)
{
A x = 1;
}
but the compiler complained with this error message:
no viable conversion from 'int' to 'A'
A x = 1;
^ ~
but when I compile with this main:
int main(void)
{
A x;
x = 1;
}
everything compiles smoothly
why does my first main not compile and how can I change the class A so that it compiles?