Sign in to follow this  

= Operator Not Working

This topic is 2378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

In a function of mine, I would like to run this for loop and create a new Tile Object after each iteration, but I get this error which says no operator '=' matches these operands. I have the error posted under the code. I do not know what is wrong and yes I have "Tile.h" included.

[code]
void function( Tile* tiles ) {
for( int i = 0; i < tiles->get_TOTAL_TILES(); i++ ) {
if( ( tileType >= 0 ) && ( tileType < tiles->get_TILE_SPRITES() ) )
tiles[ i ] = new Tile( ... ); // error here
}
}
[/code]

[code]
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Tile *' (or there is no acceptable conversion)
[/code]

Share this post


Link to post
Share on other sites
tiles[i] is of type Tile. You are trying to assign a Tile* to it, which in general will not work and practically always is a horrible idea anyway.
[code]tiles[i] = Tile(...);[/code]
should do the job.

Share this post


Link to post
Share on other sites
I would also be wary of how you are calling get_TOTAL_TILES and get_TILE_SPRITES. These should either be constants in the Tile class, or variables in a "wrapping" class such as Map.

Share this post


Link to post
Share on other sites
[quote name='BitMaster' timestamp='1310542532' post='4834655']
tiles[i] is of type Tile. You are trying to assign a Tile* to it, which in general will not work and practically always is a horrible idea anyway.
[code]tiles[i] = Tile(...);[/code]
should do the job.
[/quote]

That was it! Thanks for the help

Share this post


Link to post
Share on other sites

This topic is 2378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this