未找到函数标识符

时间:2017-03-21 17:51:14

标签: c++

我试图运行我在使用函数声明人类和骷髅数量时编写的一维战斗程序。虽然,它一直给我构建错误,说缺少函数getHumans和getSkeletons的标识符。

以下是Visual Studio在int Main()中指向缺少标识符的行:

numHumans = getHumans();
startHumans = numHumans;
cout << "\n Rolling for attack chance... \n" << "Each human has " << (humanAttack * 100) << "% chance to hit an opponent!\n";


numSkeletons = getSkeletons();
startSkeletons = numSkeletons;
cout << "\n Rolling for attack chance.. \n" << "Each skeleton has " << (skeletonAttack * 100) << "% chance to hit an opponent!\n";

以下是int Main()

之外的函数
int getHumans() {
int numHumans;
    cout << "Input the number of soldiers in the human army: ";
    cin >> numHumans;
    cout << "\nThe human army is " << numHumans << " men strong!";
    return numHumans; }


int getSkeletons() {
int numSkeletons;
    cout << "Input the number of skeletons in the skeleton army: ";
    cin >> numSkeletons;
    cout << "\nThe skeleton army is " << numSkeletons << " skeletons strong!";
    return numSkeletons; }

我不确定问题是什么,任何人都可以伸出援助之手(如果不是很明显的话,我是初学者。:P)。

1 个答案:

答案 0 :(得分:0)

很难说你发布了什么,但我猜你的getHumansgetSkeletons函数在你的main函数之后声明了。你的编译器从上到下阅读,所以如果你在调用它们时没有告诉它这些函数是什么,那么它还不知道它们是否存在。要修复它,要么复制并粘贴main之上的函数,要么正向声明它们

   int getSkeletons();
   int getHumans();

   int main(){
       ... 
  }
相关问题