C ++:使用错误C4700未初始化的局部变量“”

时间:2016-01-29 00:04:39

标签: c++

我正在尝试创建一个程序,该程序接收3个数字并按升序排列。

我已经写出了代码,但我一直收到错误说:

“使用错误C4700未经初始化的局部变量”num2“。

“错误C4700未初始化的本地变量”num3“已使用。

我已经完成了if / if-else / else之前的嵌套,但我从未遇到过这个错误。我是C ++的新手,还在学习。

我已经尝试将变量设置为默认值,然后询问一个数字,这样它就会被覆盖,然后我可以将它们相互比较。 当我没有将它们设置为0时,我也会得到一个随机的运行时错误;

以下是代码:

Button addDevButton = new Button(
        "Generate Developer", new ClickHandler() {
    public void onClick(ClickEvent event) {
        //Try and get a random team:
        teamService.getRandomTeam(new MethodCallback<Team>() {
            @Override
            public void onFailure(Method method, Throwable throwable) {
                //Developer will not be a part of any team:
                Developer d = new Developer(null, randomName(), null);
                //Send a request to add developer to database:
                devService.addDeveloper(d, new MethodCallback<String>() {
                    @Override
                    public void onFailure(Method method, Throwable throwable) {
                        Window.alert("Developer generation has failed for the following reason: \n"+throwable.getMessage());
                    }

                    @Override
                    public void onSuccess(Method method, String s) {
                        Window.alert("Developer without a team has been successfully added.");
                    }
                });
            }

            @Override
            public void onSuccess(Method method, Team team) {
                //Assign developer to this random team:
                Developer d = new Developer(null, randomName(), team);
                Window.alert( d.getTeam().toString());
                //Send a request to add developer to database:
                devService.addDeveloper(d, new MethodCallback<String>() {
                    @Override
                    public void onFailure(Method method, Throwable throwable) {
                        Window.alert("Developer generation has failed for the following reason: \n"+throwable.getMessage());
                    }

                    @Override
                    public void onSuccess(Method method, String s) {
                        Window.alert("Developer with a team has been successfully added.");
                    }
                });
            }
        });
    }
});

Here are the errors I'm getting.

1 个答案:

答案 0 :(得分:2)

:KEY

这可能应该是

cin >> num1; num2; num3; 

其他一些评论:

1)避免"use namespace std;"

2)尝试找到一个更高效的C ++开发环境,它不会让你浪费时间来解决system("pause")

这样的愚蠢问题