【问题标题】:Eclipse/CDT_C++ giving a "Semantic Error _"type XXX could not be resolved". The projects runsEclipse/CDT_C++ 给出“语义错误_”类型 XXX 无法解析”。项目运行
【发布时间】:2020-08-31 13:14:19
【问题描述】:

我对编程完全陌生,我正在学习 C++。我写了一个代码来练习带返回值的函数。代码构建并运行,但有一条错误消息,我需要一些帮助来理解它。

#include <iostream>
using namespace std;

void showMenu() {
    cout << " 1. Change personal information." << endl;
    cout << " 2. Search a Record." << endl;
    cout << " 3. Delete a Record." << endl;
    cout << " " << endl;
}

int getInput() {
    cout << "Please select a menu item: " << flush;

    int menuNum;
    cin >> menuNum;

    return menuNum;
}

void processSelection (int options){
    int password = 12;
    int record = 4;
    int record2 = 5;

    switch (options) {
    case 1:
    ...
}

int main() {
    cout << "" << endl;

    showMenu();
    int menuSel = getInput(); 
    processSelection (selection);

    return 0;
}

我省略了所有开关的东西,因为它占用了太多空间。 错误在 int main() at processSelection(selection);它说“无法解决类型'processSelection'。”

谢谢

【问题讨论】:

  • 您可能想将menuSel 而不是选择传递给processSelection 函数

标签: c++ eclipse


【解决方案1】:

您将未声明的标识符 selection 传递给 processSelection 函数。 只需将menuSel 传递给processSelection,所以你的main 应该是这样的:

int main() {
    cout << "" << endl;

    showMenu();
    int menuSel = getInput(); 
    processSelection(menuSel);

    return 0;
}

【讨论】:

  • 谢谢你,猫王。做到了。
猜你喜欢
  • 1970-01-01
  • 2015-05-28
  • 2011-05-18
  • 2013-12-01
  • 1970-01-01
  • 2017-12-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多