K****n 发帖数: 5970 | 1 class X{};
X f() {return X();}
void g1(X&) {}
void g2(const X&) {}
int main()
{
g1(f());
g2(f());
return 0;
}///:~
//----------------------------------
thinking in c++里说main函数的第一行
g1(f())
是illegal的,因为f()在直接调用的时候,将建立一个临时量,而且是const,g1()因
此无法用它当参数。
可是我在VC++ 6.0里边编译通过了并且运行了啊
请教到底是怎么回事
谢谢! | t****t 发帖数: 6806 | 2 说过多少次了, 不要用VC6来学C++, 你会越学越回去的
【在 K****n 的大作中提到】 : class X{}; : X f() {return X();} : void g1(X&) {} : void g2(const X&) {} : int main() : { : g1(f()); : g2(f()); : return 0; : }///:~
| k**f 发帖数: 372 | 3 You code compiles clean in VC++ 2008 Express, but failed g++ 3.3.4 with such
error message:
x.cpp: In function `int main()':
x.cpp:11: error: invalid initialization of non-const reference of type 'X&'
from
a temporary of type 'X'
x.cpp:5: error: in passing argument 1 of `void g1(X&)' | K****n 发帖数: 5970 | 4 啊,谢谢谢谢,VC别的版本好吗? 还是都不好?
【在 t****t 的大作中提到】 : 说过多少次了, 不要用VC6来学C++, 你会越学越回去的
| K****n 发帖数: 5970 | 5 嗯,明白了,谢谢!
such
'
【在 k**f 的大作中提到】 : You code compiles clean in VC++ 2008 Express, but failed g++ 3.3.4 with such : error message: : x.cpp: In function `int main()': : x.cpp:11: error: invalid initialization of non-const reference of type 'X&' : from : a temporary of type 'X' : x.cpp:5: error: in passing argument 1 of `void g1(X&)'
| r********d 发帖数: 23 | 6 VC enables some nonstandard extensions by default. You can disable them.
But VC6.. It's almost pre-standard... You'd better use a newer version..
【在 K****n 的大作中提到】 : 啊,谢谢谢谢,VC别的版本好吗? 还是都不好?
| K****n 发帖数: 5970 | 7 哦,了解了...
我是上大学的时候学MFC的课上老师distribute的VC6,后来好久不用,最近练练就拿出来
了.
好,换新版本...
多谢大家指点啦 | k**f 发帖数: 372 | 8
For modern compilers, you can either download VC++ 2008 Express Edition free
at Microsoft, or Eclipse CDT at http://www.eclipse.org/cdt/, along with MingW.
【在 K****n 的大作中提到】 : 哦,了解了... : 我是上大学的时候学MFC的课上老师distribute的VC6,后来好久不用,最近练练就拿出来 : 了. : 好,换新版本... : 多谢大家指点啦
| K****n 发帖数: 5970 | 9 thx! 昨天下了
用 clr test.cpp /Za 就会报错
很是有趣啊,很是有趣
free
【在 k**f 的大作中提到】 : : For modern compilers, you can either download VC++ 2008 Express Edition free : at Microsoft, or Eclipse CDT at http://www.eclipse.org/cdt/, along with MingW.
|
|