Copy constructor: is this a bug?

Michael Tsang miklcct@gmail.com
Sun Nov 1 03:57:00 GMT 2009


Program code:

#include <iostream>

struct Test {
        unsigned count;
        Test(): count() {
        }
        Test(const Test &x): count(x.count+1) {
        }
};

int main() {
        Test obj0, obj1=Test(), obj2=Test(Test());
        std::cout << obj0.count << '\n';
        std::cout << obj1.count << '\n';
        std::cout << obj2.count << '\n';
        return 0;
}

Expected result:

0
1
2

Actual result:

0
0
0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20091101/aebfe0d4/attachment.sig>


More information about the Gcc-help mailing list