Harsha
Harsha

Reputation: 5

Getting " ISO C++ forbids declaration ..." error.?

The following code is just a part of my Header file

    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 

P.S. : I am a C++ beginner

Upvotes: 0

Views: 3427

Answers (2)

john
john

Reputation: 88027

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.

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.

Upvotes: 2

BigBoss
BigBoss

Reputation: 6914

You have 3 errors in your function declaration. 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??

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);

Upvotes: 0

Related Questions