Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: binary '<' : no operator  (Read 2333 times)

0 Members and 2 Guests are viewing this topic.

Jeshuem

  • Newbie
  • *
  • Posts: 2
    • View Profile
binary '<' : no operator
« 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

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: binary '<' : no operator
« Reply #1 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.
« Last Edit: May 27, 2015, 06:23:59 pm by Jesper Juhl »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: binary '<' : no operator
« Reply #2 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.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jeshuem

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: binary '<' : no operator
« Reply #3 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
« Last Edit: May 27, 2015, 07:20:44 pm by Jeshuem »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: binary '<' : no operator
« Reply #4 on: May 27, 2015, 07:43:21 pm »
std::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.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: binary '<' : no operator
« Reply #5 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.

 

anything