I have a class with 4 constructors, and a function as below:
using namespace std;
class ABC {
public:
ABC() {
cout << "ABC()\n";
}
ABC(int) {
cout << "ABC(int)\n";
}
ABC(ABC&) {
cout << "ABC(&)\n";
}
ABC(ABC&&) {
cout << "ABC(&&)\n";
}
};
void ff(ABC t) { }
Please help me to explain some behaviours that seem strange to me (I use MSVC 2016 to compile):
1) Why do I get warning C4930: "'ABC a1(ABC (__cdecl *)(void))': prototyped function not called (was a variable definition intended?)" with the following code:
void main() {
ABC a1(ABC());
ff(ABC(5));
}
and on execution, I expect to get the following output:
ABC()
ABC(&&)
ABC(int)
ABC(&&)
but what I really get is
ABC(int)
2) Now if I change to
void main() {
ABC a1(ABC(5));
ff(ABC(5));
}
there is no more warning. But on execution, what I expect to get is
ABC(int)
ABC(&&)
ABC(int)
ABC(&&)
but what I really get is
ABC(int)
ABC(int)
3) Now
void main() {
ABC( ABC() );
ff(ABC(5));
}
It even doesn't compile. I get error C2660: "'ABC': function does not take 1 arguments".
4) Finally, why the following compiles while 3) doesn't?
void main() {
ff(ABC(5));
}