method "rand()" is ambiguous

method "rand()" is ambiguous
0.0 0



I have successfully run TestCocos2dx project on PlayBook device, but I enountered issue when I tried to make some midifications in the TestCocos2dx project.

I open the cpp file “EaseActionsTest.cpp” in “tests/EaseActionsText” folder, made no modification and tried to save it, I got the following error message:
CCRANDOM_0_1() is ambiguous

I found that CCRANDOM_0_1() is defined in “ccMacros.h” like this:
#define CCRANDOM_0_1() ((float)rand()/RAND_MAX)

Then I found that it is caused by method “rand()”.
In any cpp file if I include “cocos2d.h” and use method “rand()”, then I will get the erro “rand() is ambiguous”.
Seems that there are some difinations in “cocos2d.h” cause the ambiguousness.

Although I can successfully build the project ignoring the error message, it is disturbing, anyway to fix it?


From what I understand QNX supports both C and C**, where in C you have rand and in C** you must use random() instead. Also I found out even though sqrt() is documented in the C++ documentation, it comes up with the same error, temporary fix is using ^1/2. I’ve been advised to try import math.h and stdlib.h but didn’t try it yet.


Stick “std::” in front of the call to rand() should kill off the warning.


Yup that’s what fixed it for me :slight_smile: As well as sqrt(). Confirming.