how to use a non const function from a const function
#include <iostream>
class MyClass {
public:
void nonConstFunction() {
std::cout << "Non-const function called." << std::endl;
}
void constFunction() const {
// Call non-const function from const function
const_cast<MyClass*>(this)->nonConstFunction();
}
};
int main() {
MyClass obj;
obj.constFunction();
return 0;
}