【发布时间】:2018-01-01 01:48:43
【问题描述】:
在这个例子中,编译器说函数“list”没有定义,尽管我在下面写了一个。如果我将函数定义移到顶部所以没有原型,它编译得很好。
有人能解释一下这里发生了什么吗?
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void stuff();
void list(vector<string> things);
bool alive = true;
int main()
{
vector<string> things;
things.push_back("Lots");
things.push_back("Of");
things.push_back("Things");
do
{
cout << "What do you want to do?\n\n" << endl;
string input;
cin >> input;
if (input == "stuff")
{
stuff();
}
if (input == "list")
{
list();
}
} while (alive);
return 0;
}
void list()
{
cout << "The things are:\n\n";
for (int i = 0; i < things.size(); ++i)
{
cout << things[i] << endl;
}
}
void stuff()
{
cout << "Some stuff" << endl;
}
【问题讨论】:
-
error C2660: 'list': function does not take 0 arguments - 这甚至没有“定义”这个词。
-
好吧,我为不正确的错误道歉。在发布之前我尝试了很多东西,定义错误是最普遍的。我想这次只是碰巧不同,我没有注意到。
-
您有
void list(vector<string> things);的原型,但没有void list();的原型。也许您只需将参数提供给list()函数调用。