tags:

views:

80

answers:

4

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

+2  A: 

Optimizers get rid of uneeded stuff for you.

Gabriel
+7  A: 

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 default operator= "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...

Steve Jessop
A: 

if it can (e.g. the members do not prohibit it), it probably will generate them by default. it if doesn't need them, then it may dispose of them. otherwise, you may end up generating hundreds (or more) identical symbols (and they may be private).

Justin
A: 

You can easily inspect assembly code generated by your compiler - just be sure to turn the oiptimizations on. My guess is that none of these will be actually generated in your case.

Nemanja Trifunovic