简体   繁体   English

获得“ISO C ++禁止声明......”错误。

[英]Getting “ ISO C++ forbids declaration …” error.?

The following code is just a part of my Header file 以下代码只是我的Header文件的一部分

    double calculateDistance(const wp, &CWaypoint);
    void print(int format);
    bool less(wp_right, const &CWaypoint); 
    CWaypoint add(wp_right, const &CWaypoint);

The error is: 错误是:

g++ -O0 -g3 -Wall -c -fmessage-length=0 -o src\Waypoint.o ..\src\Waypoint.cpp
In file included from ..\src\Waypoint.cpp:15:0:
..\src\/Waypoint.h:45:33: error: 'wp' does not name a type
..\src\/Waypoint.h:45:33: error: ISO C++ forbids declaration of 'parameter' with no type
..\src\/Waypoint.h:47:12: error: 'wp_right' has not been declared
..\src\/Waypoint.h:48:16: error: 'wp_right' has not been declared 

PS : I am a C++ beginner PS:我是C ++初学者

I think you mean 我想你的意思是

double calculateDistance(const wp, CWaypoint&);

etc. 等等

& is placed after the type not before. &之后放置的类型。 You maybe have other errors, it's hard to be sure. 你可能有其他错误,很难确定。 Normally I would would both the type and the variable name in a function prototype, although the variable name is optional. 通常我会在函数原型中使用类型和变量名,尽管变量名是可选的。

OK based in the code in the comments below it seems you want 好的,基于下面评论中的代码,似乎你想要

class CWaypoint
{
...
    double calculateDistance(const CWaypoint& wp); 
    void print(int format); 
    bool less(const CWaypoint& wp_right);
    CWaypoint add(const CWaypoint& wp_right);
};

I'm not sure why you put the parameter name before the type, or why you separated the parameter name and type with a comma. 我不确定为什么要将参数名称放在类型之前,或者为什么要用逗号分隔参数名称和类型。 You had done it correctly with the other methods like getAllDataByPointer and getAllDataByReference. 您已使用其他方法(如getAllDataByPointer和getAllDataByReference)正确完成了此操作。

The rule is that commas separate method parameters, so if your method takes a single parameter there should be no comma, and if it takes two there should be one comma between the two parameter declarations, etc. 规则是逗号分隔方法参数,所以如果你的方法接受一个参数就不应该有逗号,如果它需要两个,那么两个参数声明之间应该有一个逗号等。

You have 3 errors in your function declaration. 您的函数声明中有3个错误。 First error that reported by gcc is: wp have no type: you say const wp , OK wp is a constant, but wait constant of what?? gcc报告的第一个错误是: wp没有类型:你说const wp ,OK wp是一个常量,但等待常数是什么?

Second error is you place & before the type and that's an error too. 第二个错误是你把&类型之前,这就是一个错误了。

Third, you place name of argument before it type, so in the end you should have: 第三,在键入之前放置参数名称,所以最后你应该:

double calculateDistance(const CWaypoint& wp);
bool less(const CWaypoint& wp_right);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM