mercredi 7 juillet 2021

Can anyone tell me what's wrong with the code below down?

class G
{
    public:
    G() { puts("G"); }
    G(const G& g) { puts("copy"); }
}
int main()
{
    G A();
    G B(A);
}

Compiling the code above with g++ -std=c++11 will cause error: no matching function for call to ‘G::G(G (&)())’.

But if I replace the code G A(); with G A;,everything is ok.

Can anyone tell me why ? And what's the difference between G A(); and G A;

Aucun commentaire:

Enregistrer un commentaire