I have the below function
class p{
public :
string const& PrintData() const
{
cout << "const" << str;
const_cast<ConstFunctions *>(this);
PrintData();
return str;
}
string const& PrintData()
{
cout << "non-const" << endl;
return str;
}
private :
string str="Hello";
}
int main()
{
const p p1;
p1.PrintData();
}
I am expecting the below ::
constHello non-constHello
Because i have removed the constantness of the object
But i am getting in to infinite recursive loop
(this)->PrintData()` in fact (no idea what `ConstFunctions` is)
– Lightness Races in Orbit Apr 28 '16 at 11:50