Jump to content
  • Advertisement
Sign in to follow this  
lincsimp

Quick type question..

This topic is 4816 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

Hey Apart from game programming I need to spend some time on revision... I'v ethe following function in my prog: unsigned Lookup(string input) { string lookuptable[] = {"adj","adj plural","adv","conj","noun 1","noun 2","noun 3", "noun 4","noun 5","noun irreg","noun/adj","partic","prep","pron","pron/ adj","verb", "verb 1","verb 1 dep","verb 2","verb 2 impers","verb 3","verb 3 dep","verb 4", "verb defect.","verb imperat","verb imperative","verb irreg","verb phrase"}; for(unsigned i=0;i<28;i++) { if(lookuptable=input) return i; } cout<<"type not found "<<input<<endl; return 0; } When compiled in mingw why do I get the error: helperfuncs.h could not convert `(&temp)->std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)(&ti))))' to `bool' Can anyone shed some light?? cheers

Share this post


Link to post
Share on other sites
Advertisement
Hi there!

Solution:

1. Your return value doesn't look right to me. Make it unsigned int or something.
2. In your comparison between input and lookuptable you should be using an '==' operator instead of the assignment operator of '='.
3. I would suggest changing the parameter input type to a const string& as well.

Hope that helps.

ace

Share this post


Link to post
Share on other sites
Quote:
Original post by lincsimp
Can anyone shed some light??


boldified [grin]

Quote:
Original post by lincsimp
if(lookuptable = input)


on a sidenote your method isn't efficient, you are making that array of strings everytime you enter Lookup yet it never changes between invocations, you may aswell make it a global/namespace constant.

Share this post


Link to post
Share on other sites
Quote:
Original post by lincsimp
How didn't I spot that!! It should at least have given me a decent error...

You're assigning the input string to the ith element in your array. This is perfectly legal and acceptable. Then you're testing that element for true or false, and your compiler gives you an error. If your lookup table was a const array, which it probably should be in this case, the compiler would have let you know about the mistaken assignment error.

Either way, I'd say both are decent error messages. Granted, many error messages involving the STL are often hard to read, but there are tools out there that will make that job easier as well (can't think of any specific, google for them).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!