user541686
user541686

Reputation: 210525

Are undeclared copy-constructors automatically inline?

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)?

Upvotes: 4

Views: 1036

Answers (4)

James Kanze
James Kanze

Reputation: 153929

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.

Upvotes: 8

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?

Upvotes: 1

Kerrek SB
Kerrek SB

Reputation: 477110

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.

Upvotes: 6

Puppy
Puppy

Reputation: 146940

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.

Upvotes: 1

Related Questions