编译器的奇怪行为 [英] Weird behaviour of compiler

查看:99
本文介绍了编译器的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个c ++项目,涉及管理帐户。这是项目源代码的摘录


1.logging in

展开 | 选择 | Wrap | 行号

解决方案

我看到的第一件事是login()应该返回一个用户但是有些地方它正在返回失败()。失败似乎触发了用户构造函数,因此login()返回一个损坏的对象。

C ++函数中的规则应该接收引用参数,因此没有什么可以返回的。然后函数返回值可用于通过/未通过值。


忘记返回值。即使之前发生对象声明,也会遇到异常。此外,如果你说的是正确的,那么当我直接调用login()函数时,它应该不起作用。但实际上它确实可以正常工作。


user :: operator是什么=好像?您可以发布用户类代码。


有什么例外?


另外,当你说直接调用login()时它是有效的你的意思是:

展开 | 选择 | Wrap | 行号

I was working on a project in c++,which involved managing accounts.Here is an extract of source code of project

1.logging in

Expand|Select|Wrap|Line Numbers

解决方案

The first thing I see is that login() is supposed to return a user but there are places where it''s returning fail(). That fail appears to trigger a user constructor so login() returns a corrupt object.

As a rule in C++ functions should receive reference arguments so there''s nothing to return. The function return value would then be available for pass/fail values.


Forget about returning values.It encounters the exception even before the declaration of object takes place.Moreover if what you told is right, then when I directly call login() function, it shouldn''t work.But in reality it does work properly.


What does user::operator= look like? You might post the user class code.

What exception?

Also, when you say it works when you call login() directly do you mean:

Expand|Select|Wrap|Line Numbers


这篇关于编译器的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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