Problem while trying to compile with VS 2008 Express

Want to discuss changes to the UOX3 source code? Got a code-snippet you'd like to post? Anything related to coding/programming goes here!
Post Reply
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Problem while trying to compile with VS 2008 Express

Post by Xuri »

Here's the error I get, from skills.cpp:
1>e:\uox3cvs\uox3 source\skills.cpp(104) : error C2668: 'floor' : ambiguous call to overloaded function
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\math.h(559): could be 'long double floor(long double)'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\math.h(511): or 'float floor(float)'
1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\math.h(137): or 'double floor(double)'
1> while trying to match the argument list '(int)'
The actual bit of code it chokes on, which is in void cSkills::ApplyRank( CSocket *s, CItem *c, UI08 rank, UI08 maxrank ):

Code: Select all

		// Convert item's rank to a value between 1 and 10, to fit rank system messages
		[color=red]UI08 tempRank = floor((( rank * 100 ) / maxrank ) / 10 );[/color]
Any idea how to fix this, anyone? Apart from commenting out the whole section, which is what I've been doing for a lil' while now internally :D
Last edited by Xuri on Sat Jun 25, 2011 9:29 pm, edited 1 time in total.
-= Ho Eyo He Hum =-
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Try casting it as a float, so it would look like this

Code: Select all

      // Convert item's rank to a value between 1 and 10, to fit rank system messages
      UI08 tempRank = floor(static_cast<float>((( rank * 100 ) / maxrank ) / 10 ));
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Thanks giwo, works like a charm. Also, it seems I lied; it was VS 2008 Express, not 2005. :P
-= Ho Eyo He Hum =-
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Thought that sounded weird, as I used VS2005 express with UOX just fine - once upon a time.

Anyway, you are still behind the times, VS 2010 is out now. :)
User avatar
Xuri
Site Admin
Posts: 3704
Joined: Mon Jun 02, 2003 9:11 am
Location: Norway
Has thanked: 48 times
Been thanked: 8 times
Contact:

Post by Xuri »

Yeah I installed that first, then I uninstalled and went to 2008 after getting that error the first time :P Then I tried (and failed) to find a version of 2005, so I just commented out the code and compiled without it. ;P

Another unrelated question, about using vectors in UOX3: If I create a vector and stuff some objects in it - like say, all objects a player buys from an NPC vendor, so I can iterate over the list afterwards to do some nasty stuff to the items - do I have to clear said vector or destroy it somehow after I'm done doing abusing it for my needs? Or is that handled for me automagically somehow?
-= Ho Eyo He Hum =-
giwo
Developer
Posts: 1780
Joined: Fri Jun 18, 2004 4:17 pm
Location: California
Has thanked: 0
Been thanked: 0

Post by giwo »

Personally I prefer to do explicit object cleanup, rather than trust it to happen behind the scenes. In order to "empty" a vector after you've populated it, simply do myVector.clear(); Keep in mind if you are using a vector of pointers to class objects (CItem *) it won't delete the actual object.
Post Reply