Skip to main content
GameDev.net gamedev.net
🔒 Locked

C++ code problems

Started by Tyfer Apr 12, 2001 at 2:41 AM 1 replies 300+ views
Original Post
Tyfer
Tyfer
I have this (badly written I know) line of code that simply cannot compile could someone help me, every variable is an integer. TemporaryMap[XCounter][YCounter]=CurrentMap[XCounter/2][YCounter] * HeightModifier / 100 + CurrentMap[XCounter/2+1] * (0 - HeightModifier) / 100; The error message is : Invalid Operands ''int[256]'' and ''int'' to binary ''operator *'' [256] is the size of all arrays Read, Code, Read code (& the K&R)
Read, Code, Read code (& the K&R)
Stoffel
Stoffel
We need to know all the types involved. Exactly how are these variables declared:
TemporaryMap
XCounter
YCounter
CurrentMap
HeightModifier

Also, it appears that CurrentMap is a 2D array, but on the right hand side you have "+ CurrentMap[XCounter/2+1] * ...". You''re only dereferencing one dimension, which gives you an array. This seems to be the source of your error message.

Another helpful tool when you have ugly code like this is to break it down into several lines so you can pinpoint the exact cause of the error:
int temp1 = CurrentMap[XCounter/2][YCounter];
int temp2 = HeightModifier / 100;
int temp3 = CurrentMap[XCounter/2+1]; // pretty sure this is cause of error
int temp4 = (0 - HeightModifier)/100;
TemporaryMap[XCounter][YCounter] = temp1 * temp2 + temp3 * temp4;

Once you have the problem figured out, put everything back. This is necessary in compilers that don''t give you the column number where your error occurs (I believe some do, but MSVC doesn''t).
Tyfer
Tyfer
Yeah you were right, I''ll take your advice into consideration, thanks. I guess this was one of those things where it is only obvious from someone else''s point of view

Read, Code, Read code (& the K&R)
Read, Code, Read code (& the K&R)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.