Click here to Skip to main content
15,912,072 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: implicit cast between pointers Pin
CPallini16-Jun-10 3:15
mveCPallini16-Jun-10 3:15 
AnswerRe: implicit cast between pointers Pin
Nemanja Trifunovic16-Jun-10 4:12
Nemanja Trifunovic16-Jun-10 4:12 
GeneralRe: implicit cast between pointers Pin
Iosif Murariu16-Jun-10 4:19
Iosif Murariu16-Jun-10 4:19 
GeneralRe: implicit cast between pointers Pin
Iosif Murariu16-Jun-10 4:23
Iosif Murariu16-Jun-10 4:23 
AnswerRe: implicit cast between pointers Pin
Iosif Murariu16-Jun-10 4:46
Iosif Murariu16-Jun-10 4:46 
GeneralRe: implicit cast between pointers Pin
CPallini16-Jun-10 6:11
mveCPallini16-Jun-10 6:11 
GeneralRe: implicit cast between pointers Pin
Iosif Murariu16-Jun-10 20:25
Iosif Murariu16-Jun-10 20:25 
GeneralRe: implicit cast between pointers Pin
Aescleal16-Jun-10 7:45
Aescleal16-Jun-10 7:45 
You can't implicitly cast between pointers to objects to unrelated classes. The design of C++ is such that if you want to behave like a complete nutter and do nutty things you can but you have to do something that looks ugly in return.

If you're sure that the two classes are completely type compatible and you won't have any problems later[1] you could use a set of shim functions to hide the disgustingness somewhere else. Bit like a Dorianic portrait, your code looks beautiful but up in the attic...

So if you've got:

void some_function( A *a );


implement an overide:

void some_function( B *b )
{
    some_function( reinterpret_cast<A *>( b ) );
}


Ideally what you should have done was implement a set of proxy classes between your platform specific code and the rest of your program, then you'd be just reimplementing a set of interfaces. The sort of hack you're trying to perpetrate might keep management sweet in the short term but in the long term you'll suffer with horrible code. You can't win when you fight a language's type system.

[1] Forgive me for sniggering, but the ammount of times I've heard that from so-called experienced software engineers when they've relied on the binary layout of a class only to have them condemned to using a particular compiler forever more...
GeneralRe: implicit cast between pointers Pin
Iosif Murariu16-Jun-10 20:27
Iosif Murariu16-Jun-10 20:27 
GeneralRe: implicit cast between pointers [modified] Pin
Aescleal16-Jun-10 22:37
Aescleal16-Jun-10 22:37 
QuestionPointer and Reference Pin
T.RATHA KRISHNAN16-Jun-10 2:51
T.RATHA KRISHNAN16-Jun-10 2:51 
AnswerRe: Pointer and Reference Pin
Cedric Moonen16-Jun-10 2:54
Cedric Moonen16-Jun-10 2:54 
QuestionRe: Pointer and Reference Pin
T.RATHA KRISHNAN16-Jun-10 3:05
T.RATHA KRISHNAN16-Jun-10 3:05 
AnswerRe: Pointer and Reference Pin
Cedric Moonen16-Jun-10 3:08
Cedric Moonen16-Jun-10 3:08 
QuestionReflecting programmatically changed RTL reading order on CEdit control Pin
katreddi.lakshmi16-Jun-10 2:03
katreddi.lakshmi16-Jun-10 2:03 
AnswerRe: Reflecting programmatically changed RTL reading order on CEdit control Pin
katreddi.lakshmi20-Jun-10 20:19
katreddi.lakshmi20-Jun-10 20:19 
Questionhow to load texture on a circle in open GL Pin
nearest15-Jun-10 22:27
nearest15-Jun-10 22:27 
AnswerRe: how to load texture on a circle in open GL Pin
Cedric Moonen15-Jun-10 23:31
Cedric Moonen15-Jun-10 23:31 
AnswerRe: how to load texture on a circle in open GL Pin
Cedric Moonen15-Jun-10 23:54
Cedric Moonen15-Jun-10 23:54 
AnswerRe: how to load texture on a circle in open GL Pin
Rick York16-Jun-10 16:46
mveRick York16-Jun-10 16:46 
Questiontoggle bits in a variable Pin
rupeshkp72815-Jun-10 21:29
rupeshkp72815-Jun-10 21:29 
AnswerRe: toggle bits in a variable Pin
OriginalGriff15-Jun-10 21:40
mveOriginalGriff15-Jun-10 21:40 
AnswerRe: toggle bits in a variable Pin
Cedric Moonen15-Jun-10 21:40
Cedric Moonen15-Jun-10 21:40 
QuestionLNK 2019 Pin
T.RATHA KRISHNAN15-Jun-10 21:21
T.RATHA KRISHNAN15-Jun-10 21:21 
AnswerRe: LNK 2019 Pin
Richard MacCutchan15-Jun-10 21:47
mveRichard MacCutchan15-Jun-10 21:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.