由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - c++标准函数传递一问
相关主题
关于C++中const的问题[合集] MSVS.Net里面怎么才能显示出每一次compile的完全命令?
C++ questionDJGPP下怎样用pthread.h?
question about c++ constructorintel released c++ compiler 2013
C++ 的 问题Qt Creator
a question about CASTEclipse JNI问题, 拜谢
static initialization dependency c++引用的几个基本问题,有点糊涂
free C++ compiler under Vista?[合集] 为什么 const member 不能是 static.
C语言重复定义问题C++ question
相关话题的讨论汇总
话题: c++话题: g1话题: const话题: void话题: main
进入Programming版参与讨论
1 (共1页)
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.

1 (共1页)
进入Programming版参与讨论
相关主题
C++ questiona question about CAST
请问c++为什么会编译失败?static initialization dependency c++
C arrayfree C++ compiler under Vista?
新版的 eclipse 有什么大的改进?C语言重复定义问题
关于C++中const的问题[合集] MSVS.Net里面怎么才能显示出每一次compile的完全命令?
C++ questionDJGPP下怎样用pthread.h?
question about c++ constructorintel released c++ compiler 2013
C++ 的 问题Qt Creator
相关话题的讨论汇总
话题: c++话题: g1话题: const话题: void话题: main