Advertisement Jump to content
  • Advertisement

robert_s

Member
  • Content Count

    191
  • Joined

  • Last visited

Community Reputation

122 Neutral

About robert_s

  • Rank
    Member
  1. Yes and No Fruny. :) Quote: I've also never really understood why people use if statements to return bools. Yes. I agree, there is no need for the if() in IsValid() function. Quote: It should at the very least take a const string& instead of a string parameter. so you mean like this : bool IsValid(const string &str) hm... Constant. Yes but reference I wouldnt be so sure as I already use mem_fun1_ref that calls member function through a reference. Because this is done internally by STL I am not 100% sure whther the parameters are passed by reference too. Anyway I did try that before I posted this question as I always pass strings by ref or ptr but in this case when I compile the code with bool IsValid(const string &str) then get 1 error 1 warning: c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(308): error C2529: '_Right' : reference to reference is illegal c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(309): warning C4181: qualifier applied to reference type; ignored This suggests that the parameter has already been passed by ref (see error description above). Thats why I implemented it this way (see source in my first post). Lets see what others think. Anyone, any ideas?
  2. wowww!! it does work! I cleaned solution!! :) sorry.. and thank you.
  3. Nope :) its not a type. its an iterator. See my code again.
  4. hi, I am debugging some of my code and cannot find the reason why this doesnt work as it should: class Command { public: Command(const string &name, const string &descr, const int id) { Name=name; Descr=descr; Id=id; } bool IsValid(string str) { if( Name.compare(str) == 0 ) return true; else return false; } string Name; string Descr; int Id; }; // global vector<Command>CommandList; vector<Command>::iterator CmdItr; main() { const int ID = 1; CommandList.push_back(Command("copy","copy stuff",ID)); ...... int id = GetCommandID("copy"); } int GetCommandID( string &command ) { CmdItr = find_if(CommandList.begin(), CommandList.end(), bind2nd(mem_fun1_ref(Command::IsValid), command)); if (CmdItr != CommandList.end()) { // string found } if (CmdItr == CommandList.end()) { // return Error: string not found } int id = CmdItr->Id; string descr = CmdItr->Descr; string name = CmdItr->Name; return CmdItr->Id; } I hard coded the command "copy" as I know it exists in sequence that is loaded in main(). The 'find_if' finds "copy" in the sequence but then my problem is that the iterator returned from find_if partially works. What I mean partially is that if find_if finds the command in sequence then I can display that command found by using CmdItr->Name. Its fine but it should enter the if(CmdItr != CommandList.end()) statement or if command not found it should enter the other if statement below. In my case it doesnt enter any if() which is wrong. It is annoying because if it doesnt find the string I am looking for in the sequence the app crashes when I try to return CmdItr->Name;. Of course because the iterator isnt valid but why teh if statement doest work. The iterator should be pointing at end() in case find)if doesnt find the item. Any ideas why? [Edited by - robert_s on June 25, 2004 11:15:26 AM]
  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!