Perché l'output del seguente programma è solo int3
e non int3&4
?Il costruttore di copia con parametri predefiniti non viene mai chiamato
#include <iostream>
class B
{
public:
explicit B(int i) { std::cout<<"int"<<i; }
B(const B& rhs, int i = 0) { std::cout<<"&"<<i; }
};
int main(int, char**)
{
B b(B(3), 4);
}
Comando: clang++ test.cpp -O0
Compiler: Apple versione 3.0 clang (tag/Apple/clang-211,12) (sulla base degli LLVM 3.0svn)
Stampa 'int3 & 4' per me (GCC 4.6.2,' -O3'). –
In realtà il mio g ++ 4.6.1 stampa "int3 e 4". – Duck
+1 in breve, test case completo. http://sscce.org –