Dec 11, 2010 at 8:12am UTC
Hello!
Maybe someone could help me figure out why these 2 functions do not work when in a class. Specifically, search_ign_case() would not compile.
However, brought out of class lesson and used independently,they work ok.
Here is the code:
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
class lesson
{
public:
bool comp_ign_case(char x,char y);
string :: iterator search_ign_case(string&str,const string&subst);
};
bool comp_ign_case(char x,char y);
string :: iterator search_ign_case(string&str,const string&subst);
int main (int argc, const char * argv[]) {
lesson a1;
string s("Windows and Floor will be repaired");
if (a1.search_ign_case(s,"Floors") != s.end())
cout<<endl<<"found!";
return 0;
}
bool comp_ign_case(char x,char y)
{
return tolower(x) == tolower(y);
}
string :: iterator :: lesson search_ign_case(string&str,const string&substr)
{
return search(str.begin(),str.end(),substr.begin(),substr.end(),comp_ign_case);
}
My developing tool is Xcode 3.2.5 in Mac OS X 10.6.5 on MacBook.
Thank you!
Dec 11, 2010 at 10:45am UTC
hi shredded,
many thanks for your help!
Yes, it works on my machine too.
What is it about static that makes search_ign_case() compile?
Last edited on Dec 11, 2010 at 4:21pm UTC
Dec 11, 2010 at 7:04pm UTC
Yes you have.
Thank you very much indeed.
Last edited on Dec 11, 2010 at 7:05pm UTC