copy6.c

来自「this is a gcc file, you can download it 」· C语言 代码 · 共 56 行

C
56
字号
// GROUPS passed copy-ctors/*g++ 2.3.3 will prefer using type conversions over theimplicitly generated copy constructor. This is wrong.If you explicitly define a copy constructor, it willuse it. However, the implicit copy constructor MUST becalled whenever an explicit one would have been calledalso. See below: g++ converts from and back intounsigned, instead of using the implicit copy constructor:here is the version:Reading specs from /usr/lib/gcc-lib/i386-linux/2.3.3/specsgcc version 2.3.3 /usr/lib/gcc-lib/i386-linux/2.3.3/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -Dunix -Di386 -Dlinux -D__unix__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux bug2.cc /usr/tmp/cca02008.iGNU CPP version 2.3.3 (80386, BSD syntax) /usr/lib/gcc-lib/i386-linux/2.3.3/cc1plus /usr/tmp/cca02008.i -quiet -dumpbase bug2.cc -version -o /usr/tmp/cca02008.sGNU C++ version 2.3.3 (80386, BSD syntax) compiled by GNU C version 2.3.3. as -o /usr/tmp/cca020081.o /usr/tmp/cca02008.s ld /usr/lib/crt0.o -nojump -L/usr/lib/gcc-lib/i386-linux/2.3.3 /usr/tmp/cca020081.o -lg++ -lgcc -lc -lgccOk, and here is the output:test k: constructing from scratchtest l=k: type conversion into unsignedconstructing from unsigned*/extern "C" int printf (const char *, ...);extern "C" void exit (int);int count = 0;void die () { printf ("FAIL\n"); exit (1); }struct test {	test() { if (count != 0) die (); }	test(unsigned) {	  die ();	}	operator unsigned() {	  die ();	  return 0;	}};intmain() {  test k;  test l=k;  printf ("PASS\n");  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?