I deleted the default constructor in the class ID and I have an ID field in User. When calling the User constructor I get the error use of deleted function ‘ID::ID()’
. Why is that?
Code:
<code>class ID {
public:
ID() = delete;
};
class User {
ID id;
public:
User() = delete;
User(const ID& id) {
this->id = id;
}
};
</code>
<code>class ID {
public:
ID() = delete;
};
class User {
ID id;
public:
User() = delete;
User(const ID& id) {
this->id = id;
}
};
</code>
class ID {
public:
ID() = delete;
};
class User {
ID id;
public:
User() = delete;
User(const ID& id) {
this->id = id;
}
};
But this compiles just fine:
<code>User(const ID& id) : id(id) {}
</code>
<code>User(const ID& id) : id(id) {}
</code>
User(const ID& id) : id(id) {}
Why does the compiler always call this initializing list and just ignores the this->id = id;
? (I mean not ignore, but just calls default in initializing list and error so doesn’t continue further)