Template Function Parameter
edit: Solved. Was just a stupid order of definition mistake....
So I have a function that looks like this, in the header of a class called Action:
template <class Attacker, class Defender>
static int attack_result (Attacker A, Defender D) {
//<snip>
if (random(100) < res)
return 1;
//etc.
}
And I get this when compiling:
error: there are no arguments to 'random' that depend on a template parameter, so a declaration of 'random' must be available note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
The function random() is declared in a static class called Global like this:
extern float random(int);
I'm calling Action::attack_result(...) from classes called NPC and Player, both of which are derived from a class called Creature. I don't think that's vital information, but I'll mention it in case it is. The parameters for Action::attack_result are both of Creature class.
I get why this error is being thrown, but I'm not sure how to fix it. I tried declaring Global in the Action header, I tried messing around with the keyword "using"...I can't go like this:
if (this->random(100) < res)
Because开发者_JAVA技巧 I get the following error (Creature, NPC, Player are static [and must be]):
error: 'this' is unavailable for static member functions
Going Global::random(100) does not work either:
error: incomplete type 'Global' used in nested name specifier
Any help would be very useful.
Sounds like random is in the Gloabl namespace so you need to call it like this Global::random.
精彩评论