C ++ constructor by value

Assuming I have the following (invalid) code:

struct A { A(A) {}; }; 

MSVC gives me:

 error C2652: 'A' : illegal copy constructor: first parameter must not be a 'A' 

Why does the compiler detect this as a copy constructor, and not a regular constructor?

Chapter 12.8.2 of the C ++ Standard states:

A constructor without a template for the X class is a copy constructor if its first parameter is of type X & , const X & , mutable X & or const volatile X &

I would expect the compiler to detect the above method as a regular constructor, like

 struct A { A(B) {}; }; 

whereas B is a different class.

Where is this behavior defined?

+7
c ++ language-lawyer
source share
1 answer

N4140 [class.copy] / 6

The constructor declaration for class X poorly formed if its first parameter is of type (not necessarily cv-qualified) X , and either there are no other parameters, or all other parameters have default arguments.

+5
source share

All Articles