Function does not take 6 arguments

991c178cbb1237d5e8e147aae5782cb9
0
TTTNL 101 Feb 27, 2013 at 12:00 c++

I use the template provided in the intro to c development tutorials.
I want to have my circle to circle collision checker in a seperate class so it can be used by different objects, ig. player to enemy, player to score or player to health. So I made a function checkCol in my class gameClass, which returns true if there is a collision.
The function takes the x and y coordinates of both circles and the corresponding radius and with pythagoras measures if the lenght between the middle of the circles is smaller than both the radius combined, if it is the function returns true.

classes.h:

class gameClass
{
public:
  bool checkCol( int x1, int y1, int rad1, int x2, int y2, int rad2);
};
extern gameClass gameObject;

classes.cpp:

bool gameClass::checkCol( int x1, int y1, int rad1, int x2, int y2, int rad2)
{
  if ((sqrtf( ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1) * ( y2 - y1) )) < ( rad1 + rad2 ))
  {
    return true;
  }
  else
  {
    return false;
  }
}

game.cpp:

for ( int i=0 ; i<enemies ; i++ )
{
  if ((gameObject.checkCol( player.x, player.y, player.rad, enemy[i].x, enemy[i].y, enemy[i].rad )) == true )
  {
    //do stuff
  }
}

When i run it, it gives me an error in game.cpp: “Function does not take 6 arguments:

But when i hover over both the gameObject.checkCol( //arguments ) in both game.cpp and classes.cpp it shows the correct variables, but when i hover over checkCol( //arguments ) in classes.h it shows checkCol( int x1, int y1, int) it leaves everything else out.

i tried rebuilding/cleaning the solution but that wouldn’t work.

Debug output:

1>d:\template\classes.h(79): error C2143: syntax error : missing ')' before 'constant'
1>d:\template\classes.h(79): error C2143: syntax error : missing ';' before 'constant'
1>d:\template\classes.h(79): error C2059: syntax error : ')'
1>d:\template\classes.h(79): error C2238: unexpected token(s) preceding ';'
1>d:\template\game.cpp(67): error C2660: 'gameClass::checkCol' : function does not take 6 arguments

Screenshots mousehovers:

classes.h:
VAcEDnH.png

classes.cpp:
0OWTSyE.png

game.cpp:
ZLaxyxH.png

6 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Feb 27, 2013 at 17:16

Often when you get a sequence of several compiler errors like that, the actual problem is around the first error. The compiler may be confused by the first error, or it may have skipped over a little bit of the code in an attempt to recover from the error, which can cause later errors.

In this case it looks like there is a problem in classes.h at or around line 79 (you can see the first four error messages refer to there). That may be causing the later error about the checkCol call.

Can you post what’s around line 79 in classes.h? (By the way, you can turn on line numbers in Visual Studio by going to Tools -> Options -> Text Editor -> All Languages -> Display and checking the Line Numbers box.)

991c178cbb1237d5e8e147aae5782cb9
0
TTTNL 101 Feb 27, 2013 at 18:32

line 79 is the line where “bool checkCol( //arg );” starts, pictured in the screenshot.

CXtUWSV.png

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Feb 27, 2013 at 23:02

OK. So it sounds like something is going on with “rad1” - as you can see, it’s squiggly-red-lined, and it’s interesting that your previous post showed the argument list being cut off right there.

Is “rad1” defined as something else previously in your program? For instance, is it the name of a class or something? Or do you have a #define that might be replacing it with something else? Whatever’s going on here, the compiler is sensing a problem with that “rad1” for some reason.

46407cc1bdfbd2db4f6e8876d74f990a
0
Kenneth_Gorking 101 Feb 28, 2013 at 08:40

You can also try placing the caret on ‘rad1’ and hitting F12, that should take you to whatever it is defined as.

991c178cbb1237d5e8e147aae5782cb9
0
TTTNL 101 Feb 28, 2013 at 12:12

I right clicked the rad1 in classes.h and looked up all the references, and you guessed it:
Kenneth Gorkings’ way brought me to the same place in dlgs.h

vCPYUzP.png

PaSSdMA.png

i renamed it to radi1 and radi2 (rad1 to rad16 was defined in dlgs.h) and it works now. Thanks guys!

note to everyone using the template: don’t use rad1 - rad16.

6837d514b487de395be51432d9cdd078
0
TheNut 179 Feb 28, 2013 at 12:51

Yeah, C/C++ can be annoying like that. I often like to use enums “None” and “Always” and depending on the platform I’m compiling on (mostly Linux), these are defined elsewhere and require workarounds. The GCC compiler is also quite ambiguous when reporting those errors. Something to keep in mind.