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

const function problem. casting to mutable?

P: n/a
How can I call non-const member function of a member of a class in one of
it's const qualified member function so that a compiler won't complain?

Here's the code:

bool otl_stream::eof();

class MyClass {
otl_stream m_otl_stream;
public:
bool is_valid() const {
return !m_otl_stream.eof();
}
};
The problem is the otl_stream::eof() function is not const qualified,
although it does not change the state of the object (the prototype of this
function is beyond my control).
I want to call it in my MyClass::is_valid() method which is const qualified.
How do I do this, without declaring m_otl_stream member as mutable?

--
pit3k
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Use a const_cast.
bool is_valid() const {
return ! (const_cast<otl_stream>(m_otl_stream)).eof();
}

Jul 23 '05 #2

P: n/a
Use a const_cast.
bool is_valid() const {
return ! (const_cast<otl_stream>(m_otl_stream)).eof();
}

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.