I am attempting to call a class function in my main program that takes a function as its parameter, and applies the function to a private list. I am getting the error invalid conversion from char to char (*f)(char). Hopefully I just don't understand how to pass functions as paremeters. The following are functions in my main cpp file
char ToUpper(char c)
{
char b='A';
for(char a='a';a<='z';a++)
{
if(a==c)
{
c=b;
break;
}
++b;
}
return c;
}
void upperList(LineEditor line)
{
char c;
for(int i=0;i<100;i++) //ensure iterator is at beginning of line
line.left();
for(int i=0;i<100;i++)
{
c=line.at(); //assign character current element pointed to by iterator
line.apply(ToUpper(c)); //problem: trying to apply ToUpper function to char c
line.right(); //apply function and increment iterator
}
}
And this is the apply member function
void LineEditor::apply(char (*f)(char c))
{
*it=f(c);
}
Also, in case it wasn't obvious, I tried using the cctypes toupper and tolower but they take and return integers.
charis implicitly convertable toint, or you can usestd::toupper/std::tolower. Your version ofToUpperis very inefficient.