Jump to content


Function does not take 6 arguments

c++

6 replies to this topic

#1 TTTNL

    Member

  • Members
  • PipPip
  • 47 posts

Posted 27 February 2013 - 12:00 PM

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:
Posted Image


classes.cpp:
Posted Image

game.cpp:
Posted Image

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 27 February 2013 - 05:16 PM

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.)
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 TTTNL

    Member

  • Members
  • PipPip
  • 47 posts

Posted 27 February 2013 - 06:32 PM

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

Posted Image

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 5305 posts
  • LocationBellevue, WA

Posted 27 February 2013 - 11:02 PM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 Kenneth Gorking

    Senior Member

  • Members
  • PipPipPipPip
  • 939 posts

Posted 28 February 2013 - 08:40 AM

You can also try placing the caret on 'rad1' and hitting F12, that should take you to whatever it is defined as.
"Stupid bug! You go squish now!!" - Homer Simpson

#6 TTTNL

    Member

  • Members
  • PipPip
  • 47 posts

Posted 28 February 2013 - 12:12 PM

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

Posted Image

Posted Image


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.

#7 TheNut

    Senior Member

  • Moderators
  • 1695 posts
  • LocationThornhill, ON

Posted 28 February 2013 - 12:51 PM

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.
http://www.nutty.ca - Being a nut has its advantages.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users