首页 > 解决方案 > 在 C++ 中自动生成方法

问题描述

请注意,在以下代码中,调用的函数employee_dictionary()尚未创建。如果我突出显示行号旁边的错误符号,那么我从 Eclipse IDE 获得的选项是:function 'employee_dictionary' could not be resolved'employee_dictionary' was not declared in this scope.

我假设我会看到让 Eclipse 自动创建此函数以解决错误的选项。现在我想知道我的代码是否存在根本性的问题,或者 Eclipse 是否没有我正在寻找的功能。

我是 c++ 和 Eclipse 的新手,我正在构建这个 Employee 类,因为它通常是我想学习一门新语言时开始的地方;帮助解决问题将不胜感激。我想要一个具有此功能的 IDE,所以在深入了解之前,如果我需要切换 IDE,我会的。

#include <iostream>
#include <string>

using namespace std;

class Employee
{
private:
    int id;
    int salary;
public:
    Employee(int new_id, int new_salary)
    {
        id = new_id;
        salary = new_salary;
    }

    void setID(int newInt)
    {

        if (employee_dictonary(newInt) == 0)
        {
            id = newInt;
        }
    }

    int getID()
    {
        return id;
    }

    void setSalary(int newInt)
    {
        salary = newInt;
    }

    int getSalary()
    {
        return salary;
    }

};

int main()
{
    std::cin.get();
}

标签: c++eclipse

解决方案


您需要将employee_dictionary 声明为一个函数。您正在尝试调用尚未定义的函数。这与尝试使用尚未定义的变量相同

例子:

#include <iostream>
#include <string>

using namespace std;


int main()
{
    std::cout<<bob; // bob is not declared
}

In function 'int main()':
9:16: error: 'bob' was not declared in this scope

推荐阅读