0

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 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.

7
  • 1
    If random is a static member function of Global, then you should be able to call it with if(Global::random(100) < res). Did you mean to make random a static member function rather than an extern function? Commented Aug 15, 2011 at 4:57
  • 1
    @Matthew: Have you included the appropriate header? Commented Aug 15, 2011 at 5:22
  • 1
    @Matthew: Do not mutilate this question if you got a solution, rather accept the good solution. Commented Aug 15, 2011 at 6:40
  • 1
    Why don't you post your definition of Global. Commented Aug 15, 2011 at 6:45
  • 1
    Do not mutilate this question if you do not have a problem anymore. Instead, you can answer to your own question with your fix and accept that. StackOverflow is not a chat; ideally your questions and its answers can help others in the future. 'Blanking' the question defeats that purpose. Commented Aug 15, 2011 at 7:15

1 Answer 1

1

Sounds like random is in the Gloabl namespace so you need to call it like this Global::random.

Sign up to request clarification or add additional context in comments.

2 Comments

error: incomplete type 'Global' used in nested name specifier
That means it can see a class Global; declaration but no class Global { ... }; definition. Check your #include list.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.