I have some confusion about pointers,typedefs and const. I have a function which takes a const charptr and prints that value. But when I try to compile I get some errors which I can't figure it out.
Thank you in advance.
#include <iostream>
#include <sstream>
usingnamespace std;
typedefchar* charptr;
int foe(const charptr);
int main(){
string mystring("74");
foe(mystring.c_str());
return 0;
}
int foe(const charptr var){
int tmp;
stringstream stream(var);
stream >> tmp;
cout << tmp << endl;
return tmp;
}
ex7.cpp: In function int main():
ex7.cpp:18: error: invalid conversion from const char* to char*
ex7.cpp:18: error: initializing argument 1 of int foe(char*)
Well, int foe(const charptr); resolves to int foe(char *const); because the const applies to the outmost type (which is the pointer) of a typedef while mystring.c_str() returns constchar *