我不明白编译器错误
I don't understand the compiler errors
这是一个家庭作业,所以我不希望您完全编写缺失的代码。但我需要一个相当有力的推动,因为我是新来的,需要熟悉我正在做的事情。
这是adddetailsblablabfunction()中使用的格式块
#define REPLNEFORMT3 " %-7s%7f%4fn"
第51行是函数
的原型51 void AddDetailToAccumulators(float *totpayrate, *float p);/
第85行是在主模块中调用AddDetailToAccumulators()函数
85 AddDetailToAccumulators(float *totpayrate, *float p);
171 void AddDetailToAccumulators(float *totpayrate, float *p)//3.6
172 {
173 totpayrate = p + totpayrate;
174 }
175 void PrintSummaryReport(float totpayrate, FILE * reportfile)/*, float totreg, float *totovt, float totg, float totfed,
176 float totstate, float totssi, float totnet,
177 int numemps, FILE *reportfile)//3.7*/
178
179 {
180 fprintf(stdout,REPLNEFORMT3,totpayrate);
181 fprintf(reportfile,REPLNEFORMT3,totpayrate);
182}
编译错误如下:
g++ -Wall -o "main" "main.cpp" (in directory: /media/dylan07/541C-D0D8)
main.cpp:51:49: error: expected identifier before ‘*’ token
void AddDetailToAccumulators(float *totpayrate, *float p);//, //float *totp, float reg, float *totreg,
^
main.cpp:51:50: error: expected ‘,’ or ‘...’ before ‘float’
void AddDetailToAccumulators(float *totpayrate, *float p);//, //float *totp, float reg, float *totreg,
^
main.cpp: In function ‘int main()’:
main.cpp:85:29: error: expected primary-expression before ‘float’
AddDetailToAccumulators(float *totpayrate, *float p);
^
main.cpp:85:49: error: expected primary-expression before ‘float’
AddDetailToAccumulators(float *totpayrate, *float p);
^
main.cpp: In function ‘void AddDetailToAccumulators(float*, float*)’:
main.cpp:173:19: error: invalid operands of types ‘float*’ and ‘float*’ to binary ‘operator+’
totpayrate = p + totpayrate;
^
main.cpp: In function ‘void PrintSummaryReport(float, FILE*)’:
main.cpp:180:40: warning: format ‘%s’ expects argument of type ‘char*’, but argument 3 has type ‘double’ [-Wformat=]
fprintf(stdout,REPLNEFORMT3,totpayrate);
^
main.cpp:180:40: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat=]
main.cpp:180:40: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat=]
main.cpp:181:44: warning: format ‘%s’ expects argument of type ‘char*’, but argument 3 has type ‘double’ [-Wformat=]
fprintf(reportfile,REPLNEFORMT3,totpayrate);
^
main.cpp:181:44: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat=]
main.cpp:181:44: warning: format ‘%f’ expects a matching ‘double’ argument [-Wformat=]
Compilation failed.
我希望我的格式是好的。:)
编辑:燃烧的灯,我爱你!好,这就是为什么你会得到错误。
对于第一个和第二个错误,您的*float
应该是float *
。做*float
并不意味着任何编译器,因此产生一个错误。另一方面,做float *
,告诉编译器你想要一个指向浮点数的指针,并且是完全有效的。
对于第三和第四个错误,您犯了在函数调用中包含类型的错误。别这样!它会产生一个错误。简单地删除类型,使其看起来像AddDetailToAccumulators(totpayrate, p);
,这将修复您的错误,假设topayrate和p是指向主函数中定义的浮点数的指针。
对于第五个错误,您试图将两个指针相加。这行不通!我假设您正在尝试使用指向的值,因此您需要添加解引用操作符(*),使其看起来像:*totpayrate = *p + *totpayrate;
.
对于第六个错误和警告,您的格式字符串" %-7s%7f%4fn"
告诉fprintf()
它应该期望一个字符串参数,然后两个float/double参数能够以指定的格式写入输出流。但是,您继续只给它一个float参数。我不能确切地告诉你如何修复这个问题,因为我不知道格式字符串的意图,或者你应该打印什么。我可以告诉你,你要么需要改变你的格式字符串,所以它只需要一个浮点数而不需要字符串,或者给你的PrintSummaryReport()
函数添加更多的参数,这样你就可以给fprintf()
你的格式字符串告诉它应该期待什么。
在第51行,编译器告诉您使用了间接操作符(*),但在它之前没有类型声明,因此将其更改为float * p。
在第173行,它告诉你,你没有给字符串REPLNEFORMT3足够的格式参数,它期望3个,但你只给了它一个。
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++,我收到一个无法理解的编译器错误
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- C++错误C2600:无法定义编译器生成的特殊成员函数(必须首先在类中声明)
- 我收到同义重复编译器错误。我应该如何修复"类型"X"的参数与类型"X"的参数不兼容?
- 重载方法的方式会在使用临时调用时生成编译器错误
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- 有没有办法让编译器在我放置字符串而不是 nlohmann::json 对象时抛出错误?
- 致命错误 C1001 :vs2017 15.8.4 的内部错误(编译器文件"msc1.cpp",第
- C++2440错误-编译器认为字符串是常量字符
- Clang 错误 – 编译器错误或缺少一些细节?
- 视觉C++ 2017 错误?编译器优化表达式
- 配置:错误:C++编译器无法创建可执行文件
- PHP PDO_ODBC配置:错误:C 编译器无法创建可执行文件
- 致命错误 C1001:内部编译器错误(编译器文件"MSC1.cpp",第 1794 行)
- 错误:编译器限制达到简单hello world程序的堆限制
- c++链接错误:编译器找不到函数的定义
- 生成 CImg 时出现致命错误(编译器限制)
- 抛出对齐类型时出现 Clang 运行时错误.编译器错误