gpt4 book ai didi

c++ - 出现 "ISO C++ forbids declaration ..."错误。?

转载 作者:行者123 更新时间:2023-11-28 03:28:49 33 4
gpt4 key购买 nike

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

    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

附言: 我是C++初学者

最佳答案

我想你的意思是

double calculateDistance(const wp, CWaypoint&);

等等

& 放在类型之后而不是之前。您可能还有其他错误,很难确定。通常我会在函数原型(prototype)中同时使用类型和变量名,尽管变量名是可选的。

OK,基于下面评论中的代码,您似乎想要

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 等其他方法正确地完成了它。

规则是用逗号分隔方法参数,因此如果您的方法采用单个参数,则不应使用逗号,如果采用两个参数,则两个参数声明之间应使用一个逗号,等等。

关于c++ - 出现 "ISO C++ forbids declaration ..."错误。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13168643/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com