SFML community forums

Help => Graphics => Topic started by: Jeshuem on May 27, 2015, 06:12:46 pm

Title: binary '<' : no operator
Post by: Jeshuem on May 27, 2015, 06:12:46 pm
Hi guys.

Im using the library <map> and give me errors here:

typedef pair<sf::VertexArray, int> PairTile;

        map<sf::VertexArray, int> MapTile;
 

I have no idea why  :-[.

Sorry for my bad english.

The complete error is it:

Error   5   error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const sf::VertexArray' (or there is no acceptable conversion)   c:\program files (x86)\microsoft visual studio 12.0\vc\include\xstddef   193
Title: Re: binary '<' : no operator
Post by: Jesper Juhl on May 27, 2015, 06:20:24 pm
std::map needs a comparison function for organizing the elements internally. The default, if you don't provide your own, is to use std::less() / operator<().
See http://en.cppreference.com/w/cpp/container/map

PS. This is not really SFML related but rather a general/basic C++ question. Other forums like Stackoverflow and similar will probably be better locations for questions like this.
Title: Re: binary '<' : no operator
Post by: Nexus on May 27, 2015, 06:26:05 pm
Are you sure you want to map a vertex array to an integer (and not vice versa)?

Do you even need an associative container? Your PairTile definition looks to me as if you would just want to store the values together. In that case you can use a sequential container like std::vector.
Title: Re: binary '<' : no operator
Post by: Jeshuem on May 27, 2015, 07:03:23 pm
Thanks jesper.
I need an associative container because i need the type of tile (int) to draw different textures.

I think it could be vice versa, Thanks Nexus.

EDIT:
They can't be vice versa because the int can be repeated
Title: Re: binary '<' : no operator
Post by: Jesper Juhl on May 27, 2015, 07:43:21 pm
std::multimap (http://en.cppreference.com/w/cpp/container/multimap) exists.
But, as Nexus said; using a vertexarray as key seems rather strange.
Are you sure you don't just want a vector (possibly of pairs and possibly sorted)?
What exactely are you trying to achieve? Maybe if you describe the problem you are trying to solve we can help you better.
Title: Re: binary '<' : no operator
Post by: Mario on May 28, 2015, 02:28:56 pm
I'd just use a two-dimensional array for this. Unless you're having lots of gaps, a map sounds rather unintuitive.

If your tile maps are rather limited anyway, you might be getting away cramming both coordinates into an integer (or long integer) for your index key.