Hello, thank for your answer.
The use of const_cast is suggested by Bruce Eckel in Thinking C++ vol. 1 at the chapter 3 (The C in C++).
He said that a const pointer to an object can't be assigned to a nonconst pointer.
I made your changes and the compiler does, but other compilers (Borland) requires const_cast...
Thank you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, I wrote a class that use a copy constructor with a const reference to my class...
There is a fragment of my code...
class r_ruota {
friend ostream& operator << (ostream&, const r_ruota&);
public:
r_ruota(const r_ruota& r) {
// costruttore copia
vector<estratto>::iterator it;
no_ruota=r.no_ruota;
for (it=const_cast<vector<estratto>::iterator>(r.xresult.begin());
it!=const_cast<vector<estratto>::iterator>(r.xresult.end());
it++) {
xresult.push_back(*it);
}
}
r_ruota() : no_ruota(0) { };
r_ruota(int num) : no_ruota(num) { };
int no_ruota;
vector<estratto> xresult;
};
I got problems with const_cast and Dev-Cpp 4.9.7.0.
Dev-C++ 4 compile the source code, also Borland C++ compile it...
Can anyone help me?
Why const_cast??
r isn't changed, is it?
try without const_cast
Hello, thank for your answer.
The use of const_cast is suggested by Bruce Eckel in Thinking C++ vol. 1 at the chapter 3 (The C in C++).
He said that a const pointer to an object can't be assigned to a nonconst pointer.
I made your changes and the compiler does, but other compilers (Borland) requires const_cast...
Thank you.