【发布时间】:2021-09-14 16:21:35
【问题描述】:
我的代码编译失败,我收到这些错误消息。我看过类似的问题,但似乎没有什么是对的。我不明白是什么导致了问题,因为我已经声明了我的函数并在 main 下定义了它。
declaration is incompatible with "void reprchar(char ch, int n)" (declared at line 18)C/C++(147) [4,6]
variable or field 'reprchar' declared void gcc [4,14]
'reprchar' was not declared in this scope gcc [7,5]
expression preceding parentheses of apparent call must have (pointer-to-) function type C/C++(109) [7,5]
expression preceding parentheses of apparent call must have (pointer-to-) function type C/C++(109) [9,5]
expression preceding parentheses of apparent call must have (pointer-to-) function type C/C++(109) [14,5]
declaration is incompatible with "void reprchar" (declared at line 4) C/C++(147) [18,6]
代码是
#include <iostream>
using namespace std;
void reprchar('a', 54);
int main() {
reprchar('*', 45);
cout << "Data type Range" << endl;
reprchar('-', 23);
cout << "char -128 to 127" << endl
<< "short -32,768 to 32,767" << endl
<< "int System Dependent" << endl
<< "double -2,147,483,648 to 2,147,483,647" << endl;
reprchar('*', 45);
return 0;
}
void reprchar(char ch, int n) {
for(int i=0; i<n; i++) {
cout << ch;
cout << endl;
}
}
【问题讨论】:
-
这个 void reprchar('a', 54);不是函数声明。您需要声明参数而不是使用表达式。
-
您只需要
void reprchar(char, int);进行声明。你现在拥有的是一个函数调用。 -
@Zoso
void reprchar('char, int);不起作用 -
void reprchar('a', 54);半声明。半调用。全部不可编译。 -
@0___________ 有问题的引号?
标签: c++ visual-studio-code compiler-errors