let’s assume I have some class A:
header
class A{
int x;
int value() {return x};
};
main
A a;
cout << a.value();
my question is: will my compiler produce d'tor copy c'tor and operator= for me or not (cause it actually doesn’t need it)
EDITED
does it write d’tor for me at all, cause it seems to be useless, may you give please example if I’m wrong
In principle, yes for the ctor and dtor, which are “used”. No for the
operator=: the default functions are only generated if used, which is quite important since for some classes the defaultoperator=“wouldn’t work”, so it’s not available.In practice, the auto-generated ctor and dtor of this class do nothing. A compiler good enough to use for real work, will ensure that their theoretical existence doesn’t result in any code being generated[*].
[*] I think. It wouldn’t necessarily be all that bad to have a bunch of do-nothing-and-return functions in the binary. It would likely be quite bad if the compiler couldn’t remove the calls to them, though – not for your program, but for bigger programs with millions of such objects…