DF
Size: a a a
DF
DF
VU
AT
As an example, look again at the setTitle call we just saw that failed to compile under some implementations:
EmplDSet::iterator i = se.find(selectedlD);
if (i != se.end()) {
i->setTitle("Corporate Deity");
// some STL implementations will reject this line because *i is const
}
To get this to compile and behave correctly, we must cast away the constness of *i. Here's the correct way to do it:
if (i != se.end()) {
const_cast<Employee&>(*i).setTitle("Corporate Deity");
// cast away constness of*i
}
АР
ПК
As an example, look again at the setTitle call we just saw that failed to compile under some implementations:
EmplDSet::iterator i = se.find(selectedlD);
if (i != se.end()) {
i->setTitle("Corporate Deity");
// some STL implementations will reject this line because *i is const
}
To get this to compile and behave correctly, we must cast away the constness of *i. Here's the correct way to do it:
if (i != se.end()) {
const_cast<Employee&>(*i).setTitle("Corporate Deity");
// cast away constness of*i
}
DF
AT
ПК
As an example, look again at the setTitle call we just saw that failed to compile under some implementations:
EmplDSet::iterator i = se.find(selectedlD);
if (i != se.end()) {
i->setTitle("Corporate Deity");
// some STL implementations will reject this line because *i is const
}
To get this to compile and behave correctly, we must cast away the constness of *i. Here's the correct way to do it:
if (i != se.end()) {
const_cast<Employee&>(*i).setTitle("Corporate Deity");
// cast away constness of*i
}
m
As an example, look again at the setTitle call we just saw that failed to compile under some implementations:
EmplDSet::iterator i = se.find(selectedlD);
if (i != se.end()) {
i->setTitle("Corporate Deity");
// some STL implementations will reject this line because *i is const
}
To get this to compile and behave correctly, we must cast away the constness of *i. Here's the correct way to do it:
if (i != se.end()) {
const_cast<Employee&>(*i).setTitle("Corporate Deity");
// cast away constness of*i
}
AT
m
namespace std
, скорее всего о добавлении в свой неймспейс.m
int i = 0;В этом коде нет UB, но компилятор не подскажет когда оно появится.
const int& cr = i;
const_cast<int&>(cr) = 42;
m
AT
DF