实参太多 [英] Too many arguments to function
本文介绍了实参太多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从头文件中得到以下错误:太多参数无法使用void printCandidateReport();
.我对C ++相当陌生,只需要一些正确方向的指导即可解决此错误.
I am getting this error from my header file: too many arguments to function void printCandidateReport();
. I am fairly new to C++ and just need some guidance in the right direction to solving this error.
我的头文件如下:
#ifndef CANDIDATE_H_INCLUDED
#define CANDIDATE_H_INCLUDED
// Max # of candidates permitted by this program
const int maxCandidates = 10;
// How many candidates in the national election?
int nCandidates;
// How many candidates in the primary for the state being processed
int nCandidatesInPrimary;
// Names of the candidates participating in this state's primary
extern std::string candidate[maxCandidates];
// Names of all candidates participating in the national election
std::string candidateNames[maxCandidates];
// How many votes wone by each candiate in this state's primary
int votesForCandidate[maxCandidates];
void readCandidates ();
void printCandidateReport ();
int findCandidate();
#endif
和调用此头文件的文件:
and the file calling this header file:
#include <iostream>
#include "candidate.h"
/**
* Find the candidate with the indicated name. Returns the array index
* for the candidate if found, nCandidates if it cannot be found.
*/
int findCandidate(std::string name) {
int result = nCandidates;
for (int i = 0; i < nCandidates && result == nCandidates; ++i)
if (candidateNames[i] == name)
result = i;
return result;
}
/**
* Print the report line for the indicated candidate
*/
void printCandidateReport(int candidateNum) {
int requiredToWin = (2 * totalDelegates + 2) / 3; // Note: the +2 rounds up
if (delegatesWon[candidateNum] >= requiredToWin)
cout << "* ";
else
cout << " ";
cout << delegatesWon[candidateNum] << " " << candidateNames[candidateNum]
<< endl;
}
/**
* read the list of candidate names, initializing their delegate counts to 0.
*/
void readCandidates() {
cin >> nCandidates;
string line;
getline(cin, line);
for (int i = 0; i < nCandidates; ++i) {
getline(cin, candidateNames[i]);
delegatesWon[i] = 0;
}
}
为什么会出现此错误,我该如何解决?
why am I getting this error and how can I fix it?
推荐答案
在头文件中,您声明:
void printCandidateReport ();
但是在实现上是:
void printCandidateReport(int candidateNum){...}
将头文件更改为
void printCandidateReport(int candidateNum);
这篇关于实参太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文