How to check if object is const or not?
c++
Solution
To solve my problem i needed to overload functions
void Vec(Vec const &Vecc) const{
std::cout << "YES" << std::endl;
}
void Vec(Vec const&Vecc){
std::cout << "YES" << std::endl;
}
void Vec(Vec &Vecc) const {
std::cout << "NO" << std::endl;
}
void Vec(Vec &Vecc) {
std::cout << "NO" << std::endl;
}
Problem
My problem is that I have no idea how to check if object is const. I can only use C++98. How can I check if object have const modifier? How to overload functions properly? ``` int main(){ Vec x; const Vec y; cout<<"Is x const? "; y.IfConst(x); // cout << "no" cout<<"\n"; cout<<"Is x const? "; x.IfConst(x) // cout << "no" cout<<"\n"; cout<<"Is y const? "; x.IfConst(y); // cout << "yes" cout<<"\n"; cout<<"Is y const? "; y.IfConst(y); // cout << "yes" cout<<"\n"; /**/ } ``` I need output look like: is x const? no is x const? no is y const? yes is y const? yes I used: ``` void Vec::IsConst(Vec const &vecc) const{ std::cout << "YES" << std::endl; } void Vec::IsConst(Vec const &vecc) { std::cout << "NO" << std::endl; } ```