Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
767 views
in Technique[技术] by (71.8m points)

c++ - reinterpret_cast casts away qualifiers

I add an issue on reinterpreting a variable and I don't know why..

int ProgressBar(const uint64_t data_sent, const uint64_t data_total, void const *const data)
{
    Dialog *dialog = reinterpret_cast<Dialog*> (data);
    dialog->setValue((data_sent *100) / data_total);
}

the reinterpret_cast seems not allowed and say

reinterpret_cast from 'const void *) to Dialog * casts away qualifiers

Any idea

question from:https://stackoverflow.com/questions/27995692/reinterpret-cast-casts-away-qualifiers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As Nick Strupat stated in comment,

reinterpret_cast can't cast away cv-qualifiers

So you can use reinterpret_cast and const_cast together.

Dialog *dialog = const_cast<Dialog*>(reinterpret_cast<const Dialog *>(data));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...