c++ - 在 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();
}
解决方案
您需要将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
推荐阅读
- python - 如何在模型中使用 tf.gradients 并仍然使用自定义训练循环?
- string - 是否有一个字符串函数可以分隔用斜杠连接的单词?
- openpyxl - XlsxWriter 中的追加模式损坏现有文件
- webpack - Webpack css-loader UnhandledPromiseRejectionWarning: Error: The module created for a LoaderDependency must have an original source
- javascript - 从 Web 应用程序中的过滤数组自动完成
- php - MYSQL SELECT 多行成一行
- r - 如何计算与连续函数的平均密度相对应的 x 值?
- flutter - Flutter 中的抽屉到底部导航栏
- python - 如何将字符串的字符定义为“索引”,然后计算两个方向的字符频率?
- python - 如何在 python 中使用用户输入和字符串操作制作框架框?