无法识别功能调用

时间:2019-07-17 17:15:50

标签: c++

我正在为一项任务编写一个神奇的八球程序。我的所有函数调用都起作用,除了一个。我不断收到错误消息,指出没有匹配的函数要调用。我们使用了原型的副本来打电话,所以我知道这不是错字。我无法弄清楚为什么它对我来说设置正确。

main.cpp:

int main() {

    const int MAXSIZE = 100;
    int size;
    string responses[MAXSIZE];
    string categories[MAXSIZE];
    srand(time(0));

    start:
    cout << "A. Read responses/categories from file" << endl;
    cout << "B. Play Magic Eight Ball" << endl;
    cout << "C. Sort by responses" << endl;
    cout << "D. Sort by categories" << endl;
    cout << "E. Write responses/categories to a file" << endl;
    cin >> input;
    ifstream infile;
    ofstream outfile;

    switch (input) {
        case ('A'):
        case ('a'):

            readResponses(infile, responses, categories , MAXSIZE, size);
            break;
    ...

functions.h:

#include <iostream>     
#include <string>      
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

#ifndef UNTITLED_FUNCTIONS_H
#define UNTITLED_FUNCTIONS_H

void readResponses(ifstream &infile, string responses[], string categories ,const int MAXSIZE, int &size );

#endif //UNTITLED_FUNCTIONS_H

functions.cpp:

#include <iostream>     
#include <string>      
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include "functions.h"
using namespace std;



void readResponses(ifstream &infile, string responses[], string 
    categories[], const int MAXSIZE, int &size ) {

    string s;
    int num = 0;
    infile.open("magic.txt");

    size = 0;
    while (getline(infile,s) && (num < MAXSIZE)) {

        responses[num] = s;
        getline(infile, s);
        categories[num] = s;
        num++;
    }
    size = num;

    infile.close();

}

1 个答案:

答案 0 :(得分:2)

在函数readResponses中,您声明了string categories,并在定义中使用了string categories[]