函数必须返回一个值 [英] Function must return a value

查看:408
本文介绍了函数必须返回一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有没有理由说VC2003 C ++编译器发出错误功能

必须返回一个值全局函数而不是类成员

函数?


例如:


int test()< br $>
{


}

//生成错误


class Test

{

int test(){} //不会产生错误

};


我正在使用/ clr进行编译,如果这有任何区别(尽管

问题中的课程没有得到管理)。警告级别为3,但即使是4,它也不会出现
,正如我所说的那样,错误会被全局函数抛出。一次

我希望我的代码不要编译:-)


Steve

Hi,

Is there any reason why the VC2003 C++ compiler emits the error "Function
must return a value" for global functions and not for class member
functions?

For example:

int test()
{

}
// Generates the error

class Test
{
int test() {} // Doesn''t generate the error
};

I''m compiling with /clr if that makes any difference (though the class in
question is not managed). Warning level''s 3, but even on four it doesn''t
appear and as I''ve said, the error gets thrown up for global funcs. For once
I WANT my code not to compile :-)

Steve

推荐答案

2004年5月18日星期二12:52:03 +0100,Steve McLellan < sjm.NOSPAM at

fixerlabs DOT com>写道:
On Tue, 18 May 2004 12:52:03 +0100, "Steve McLellan" <sjm.NOSPAM AT
fixerlabs DOT com> wrote:


有没有理由为什么VC2003 C ++编译器发出错误功能
必须返回一个值全局功能而不是班级成员
功能?

例如:

int test()


}
//生成错误

类测试
{
int test(){} //不会产生错误
};

我正在使用/ clr进行编译,如果这有任何区别(虽然
问题中的类没有管理)。警告级别为3,但即使在四级也没有出现,正如我所说,错误会被全局函数抛出。一次
我想要我的代码不要编译: - )
Hi,

Is there any reason why the VC2003 C++ compiler emits the error "Function
must return a value" for global functions and not for class member
functions?

For example:

int test()
{

}
// Generates the error

class Test
{
int test() {} // Doesn''t generate the error
};

I''m compiling with /clr if that makes any difference (though the class in
question is not managed). Warning level''s 3, but even on four it doesn''t
appear and as I''ve said, the error gets thrown up for global funcs. For once
I WANT my code not to compile :-)




这也不会产生错误:

inline int test(){}

但是,如果您实际尝试调用Test :: test或上面的测试,则会生成

错误。请注意,对于C ++编译器而言,这不是诊断所需要的




Tom

-

C ++常见问题解答: http://www.parashift.com / c ++ - faq-lite /

C FAQ: http://www.eskimo.com/~scs/C-faq/top.html


" tom_usenet" <到******** @ hotmail.com>在消息中写道

news:la ******************************** @ 4ax.com ...
"tom_usenet" <to********@hotmail.com> wrote in message
news:la********************************@4ax.com...
2004年5月18日星期二12:52:03 +0100,Steve McLellan < sjm.NOSPAM at
fixerlabs DOT com>写道:
On Tue, 18 May 2004 12:52:03 +0100, "Steve McLellan" <sjm.NOSPAM AT
fixerlabs DOT com> wrote:


有没有理由为什么VC2003 C ++编译器发出错误功能
必须返回一个值全局功能而不是班级成员
功能?

例如:

int test()


}
//生成错误

类测试
{
int test(){} //不会产生错误
};

我正在使用/ clr进行编译,如果这有任何区别(虽然
问题中的类没有管理)。警告级别为3,但即使在四级也没有出现,正如我所说,错误会被全局函数抛出。对于
一次我希望我的代码不要编译: - )
Hi,

Is there any reason why the VC2003 C++ compiler emits the error "Function
must return a value" for global functions and not for class member
functions?

For example:

int test()
{

}
// Generates the error

class Test
{
int test() {} // Doesn''t generate the error
};

I''m compiling with /clr if that makes any difference (though the class in
question is not managed). Warning level''s 3, but even on four it doesn''t
appear and as I''ve said, the error gets thrown up for global funcs. For onceI WANT my code not to compile :-)



这也不会产生错误:
inline int test(){} 错误。请注意,这不是诊断要求C ++编译器符合要求。



This doesn''t generate an error either:
inline int test(){}

However, if you actually try to call Test::test or the test above, the
error is then generated. Note that this is not a diagnostic required
for a C++ compiler to be conforming.







这就是问题;我叫它。我的函数返回一个向量,并且从托管类中的函数调用
。如果没有返回,我

在运行时获得空引用异常,并且没有编译器麻烦。我理解,我不一定会因为编译出来的函数而错误。如果我有时间的话,我会试着打破一个简单的测试用例,更像是我的

代码。


干杯,


Steve



Hi,

This is the problem; I AM calling it. My function is returning a vector, and
is being called from a function in a managed class. If there''s no return, I
get a null reference exception at runtime, and no compiler troubles. I
understand that I won''t necessarily get errors for functions that will be
compiled out. I''ll try to knock up a simple test case that''s more like my
code later if I have time.

Cheers,

Steve


Steve McLellan写道:
Steve McLellan wrote:


有吗VC2003 C ++编译器发出错误的原因
函数必须返回值对于全局函数而不是为类
成员函数?
Hi,

Is there any reason why the VC2003 C++ compiler emits the error
"Function must return a value" for global functions and not for class
member functions?




我无法在这里重现:

- ---

class X

{

public:

int test(){}

};


int main()

{

X x;

x.test();

返回0;

}

----


此代码正确地给出了C4716错误消息。这种情况发生在没有/ clr开关的情况下或者没有/ br开关,实际上当我将X变成__gc

类时仍然会发生这种情况。你能发一个显示你症状的完整例子吗?


-

Sven Groot

http://unforgiven.bloghorn.com



I can''t get that to reproduce here:
----
class X
{
public:
int test() { }
};

int main()
{
X x;
x.test();
return 0;
}
----

This code properly gives the C4716 error message. This happens with or
without the /clr switch, and in fact still happens when I turn X into a __gc
class. Could you post a complete example that shows your symptoms?

--
Sven Groot

http://unforgiven.bloghorn.com


这篇关于函数必须返回一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆