繁体   English   中英

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

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

以下代码只是我的Header文件的一部分

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

错误是:

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:我是C ++初学者

我想你的意思是

double calculateDistance(const wp, CWaypoint&);

等等

&之后放置的类型。 你可能有其他错误,很难确定。 通常我会在函数原型中使用类型和变量名,尽管变量名是可选的。

好的,基于下面评论中的代码,似乎你想要

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

我不确定为什么要将参数名称放在类型之前,或者为什么要用逗号分隔参数名称和类型。 您已使用其他方法(如getAllDataByPointer和getAllDataByReference)正确完成了此操作。

规则是逗号分隔方法参数,所以如果你的方法接受一个参数就不应该有逗号,如果它需要两个,那么两个参数声明之间应该有一个逗号等。

您的函数声明中有3个错误。 gcc报告的第一个错误是: wp没有类型:你说const wp ,OK wp是一个常量,但等待常数是什么?

第二个错误是你把&类型之前,这就是一个错误了。

第三,在键入之前放置参数名称,所以最后你应该:

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