C++ error C2064

term does not evaluate to a function taking 0 arguments

Page 1 of 1

4 Replies - 1844 Views - Last Post: 30 April 2010 - 08:52 PM Rate Topic: -----

#1 Mawhonic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 22-April 10

C++ error C2064

Posted 30 April 2010 - 08:04 PM

So I've got this random function in my main. Welp, it worked yesterday, but after messing with the code and forgetting what I changed, now I keep getting this error.

error C2064: term does not evaluate to a function taking 0 arguments

And the function is:
int main()
 {
	//int n = 3000;
	srand((unsigned)time(0));
	int rand;
	int lowest=1, highest=3;
	int range=(highest-lowest)+1;

	for(int index=0; index<20; index++)
	{
		//a1 = mvx1;
		//b1 = mvy1;

		rand = lowest+int(range*rand()/(RAND_MAX + 1.0));
		cout << rand << endl;
        }
}


- So does anyone see the problem? I can't find it yet. Thanks.

Admin Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)

Is This A Good Question/Topic? 0
  • +

Replies To: C++ error C2064

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: C++ error C2064

Posted 30 April 2010 - 08:10 PM

You can't use rand as a variable name because it conflicts with the function rand().


And for future reference -- it would be helpful to include the line number that is part of the error message.

This post has been edited by r.stiltskin: 30 April 2010 - 08:11 PM

Was This Post Helpful? 3
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: C++ error C2064

Posted 30 April 2010 - 08:12 PM

Try changing this line

srand((unsigned)time(0));



to this

srand((unsigned int)time(0));



EDIT: Good catch r.stiltskin, I didn't even see that
Was This Post Helpful? 0
  • +
  • -

#4 Mawhonic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 22-April 10

Re: C++ error C2064

Posted 30 April 2010 - 08:51 PM

The error occurs at the line:

rand = lowest+int(range*rand()/(RAND_MAX + 1.0));

Well thanks! It was the rand. I changed it to randint and it works!
Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: C++ error C2064

Posted 30 April 2010 - 08:52 PM

And r.stiltskin gave you the answer.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1