By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,227 Members | 1,226 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,227 IT Pros & Developers. It's quick & easy.

call non-const function

P: n/a
GFXMLTree* Seek4Node(LPCTSTR name);
const GFXMLTree* Seek4Node(LPCTSTR name) const
{
return Seek4Node(name); // Force to call the first version
}
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, 'g', 64, "ba", 46, 10);}
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Gernot Frisch wrote:
GFXMLTree* Seek4Node(LPCTSTR name);
const GFXMLTree* Seek4Node(LPCTSTR name) const
{
return Seek4Node(name); // Force to call the first version
}


You can only safely do that if you know that your object was in fact
non-const when it was created. But that's only known by the caller,
not inside the function. So, before calling the overloaded member
function, cast the constness away.

V
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.