[C++] Problem z kontenerem std::map [rozwiązano]
Ostatnio zmodyfikowano 2013-01-25 11:15
kubawal Temat założony przez niniejszego użytkownika |
[C++] Problem z kontenerem std::map [rozwiązano] » 2013-01-25 10:45:10 Witam! Przy pisaniu pewnej gry napotkałem problem. Mianowicie mam taka klasę: #include <SFML/Graphics.hpp> #include <map> using namespace std; using namespace sf;
class TextureMenager { public: enum TexType { Grass, Crack, } const Texture & GetTexture( TexType tp ) const { return txtab[ tp ]; } private: map < TexType, sf::Texture > txtab; };
Przy próbie kompilacji VC wywala następujące błedy: 1>error C2678: binary '[' : no operator found which takes a left-hand operand of type 'const std::map<_Kty,_Ty>' (or there is no acceptable conversion) 1> with 1> [ 1> _Kty=TextureMenager::TexType, 1> _Ty=sf::Texture 1> ] 1> could be 'sf::Texture &std::map<_Kty,_Ty>::operator [](TextureMenager::TexType &&)' 1> with 1> [ 1> _Kty=TextureMenager::TexType, 1> _Ty=sf::Texture 1> ] 1> or 'sf::Texture &std::map<_Kty,_Ty>::operator [](const TextureMenager::TexType &)' 1> with 1> [ 1> _Kty=TextureMenager::TexType, 1> _Ty=sf::Texture 1> ] 1> while trying to match the argument list '(const std::map<_Kty,_Ty>, const TextureMenager::TexType)' 1> with 1> [ 1> _Kty=TextureMenager::TexType, 1> _Ty=sf::Texture 1> ] ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Nie wiem, co się stało. Kubawal |
|
DejaVu |
» 2013-01-25 10:58:02 Nie możesz mieć metody typu const oraz zwracać const Texture, ponieważ operator [] nie posiada wersji implementacji constowej wspomnianego operatora. |
|
kubawal Temat założony przez niniejszego użytkownika |
» 2013-01-25 11:15:33 Dzięki, działa! Zamykam. |
|
« 1 » |