Question

Are undeclared (auto-generated) copy constructors automatically marked as inline?

If so, and if I don't want them to be marked as inline, does that mean I have to define one manually and copy every single member I need by hand (assuming I'm not using C++11, so that there's no = default to take advantage of)?

Was it helpful?

Solution

They're treated as if they were declared inline (which doesn't necessarily mean that they will be inlined). And yes, in pre-C++11, the only way to prevent their being inline was to declare and define them manually, copying every member and every base class explicitly in the initializer list.

OTHER TIPS

Yes. From C++11, 12.8/11:

An implicitly-declared copy/move constructor is an inline public member of its class.

I would strongly suggest reading all of 12.8 if you like to get more familiar with copy and move constructors.

They are, I believe. However, for a such a compiler-defined function, the difference between inline and not is non-observable. And yes, you would have to define your own for it to be non-inline, although why you would want such a thing is beyond me. It makes no difference to the semantics and won't affect the compiler's inlining.

Implicitly defined special member functions are inline and they must be as they can be implicitly generated in multiple translation units. The meaning of inline is that it can be defined in multiple translation units without violating the ODR, not that the code will actually be inlined (this depends on the type and the compiler).

Why don't you want the copy constructor to be inline?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top