So I have class that uses conversion operator to int
class Tiny
{
char v;
void assign(int i) {if (i&~077) throw Bad_range(); v = i;}
public:
class Bad_range {};
Tiny() : v('0') {}
Tiny(int i) {assign(i);}
Tiny& operator=(int i) {assign(i); return *this;};
operator int() const {return v;}
};
My question is, why does my compiler give me an error when I use default constructor in this case:
Tiny x();
Tiny y = x + 4;
cout << y;
but work perfectly fine when:
Tiny x(6);
Tiny y = x + 4;
cout << y;
(prints out 10)