Click here to Skip to main content
15,892,575 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Boost Library Pin
002comp10-Aug-10 2:48
002comp10-Aug-10 2:48 
GeneralRe: Boost Library Pin
Niklas L10-Aug-10 2:58
Niklas L10-Aug-10 2:58 
GeneralRe: Boost Library Pin
002comp10-Aug-10 18:02
002comp10-Aug-10 18:02 
GeneralRe: Boost Library Pin
Niklas L10-Aug-10 22:13
Niklas L10-Aug-10 22:13 
Questionany idea for "auto-cast"ing? Pin
includeh1010-Aug-10 0:24
includeh1010-Aug-10 0:24 
AnswerRe: any idea for "auto-cast"ing? Pin
Sauro Viti10-Aug-10 0:44
professionalSauro Viti10-Aug-10 0:44 
AnswerRe: any idea for "auto-cast"ing? Pin
CPallini10-Aug-10 0:45
mveCPallini10-Aug-10 0:45 
AnswerRe: any idea for "auto-cast"ing? PinPopular
Aescleal10-Aug-10 1:29
Aescleal10-Aug-10 1:29 
It's easy to do, as others have said you can just use dynamic_cast, but should you really do it? Generally no. As soon as you start downcasting (with a few exceptions - pardon the pun) it's a sign that you've missed a virtual function somewhere. And as soon as you start missing virtual functions you're coupling your code more tightly than it needs to be - which usually ends up with ages compile times and people becoming scared of anything in an h file.

So if you've got a situation like...

I *p = <something set yonks ago>;

if( A *a = dynamic_cast<A *>( p ) )
{
    a->do_a_specific_thing();
}
else if( B *b = dynamic_cast<B *>( p ) )
{
    b->do_b_specific_thing();
}


think of modifying I instead so you end up with:

I *p = <something set yonks ago>;

p->do_specific_thing();


You make it easier to maintain (if you're maintaining the code you don't have to know about A and B) and extend (you can add another subclass without changing the client code). So if you're using dynamic_cast<> consider if you really need the client code to know about the concrete type of the objects it's operating on.

(And the same goes for type fields, they're even more useless and redundant than dynamic_cast).

Cheers,

Ash


Cheers,

Ash
GeneralRe: any idea for "auto-cast"ing? Pin
Chris Losinger10-Aug-10 5:29
professionalChris Losinger10-Aug-10 5:29 
GeneralRe: any idea for "auto-cast"ing? Pin
Aescleal10-Aug-10 5:59
Aescleal10-Aug-10 5:59 
GeneralRe: any idea for "auto-cast"ing? Pin
Chris Losinger10-Aug-10 6:09
professionalChris Losinger10-Aug-10 6:09 
GeneralRe: any idea for "auto-cast"ing? Pin
Aescleal10-Aug-10 10:11
Aescleal10-Aug-10 10:11 
GeneralRe: any idea for "auto-cast"ing? Pin
Chris Losinger10-Aug-10 10:33
professionalChris Losinger10-Aug-10 10:33 
GeneralRe: any idea for "auto-cast"ing? Pin
Aescleal10-Aug-10 19:53
Aescleal10-Aug-10 19:53 
GeneralRe: any idea for "auto-cast"ing? Pin
Moak10-Aug-10 23:33
Moak10-Aug-10 23:33 
GeneralRe: any idea for "auto-cast"ing? Pin
Chris Losinger11-Aug-10 1:08
professionalChris Losinger11-Aug-10 1:08 
QuestionLINK : fatal error LNK1104: cannot open file 'MyCplusplusWithSTL.lib' after converting VS2008 to VS2010 Pin
Chesnokov Yuriy9-Aug-10 22:43
professionalChesnokov Yuriy9-Aug-10 22:43 
AnswerRe: LINK : fatal error LNK1104: cannot open file 'MyCplusplusWithSTL.lib' after converting VS2008 to VS2010 Pin
Richard MacCutchan10-Aug-10 0:01
mveRichard MacCutchan10-Aug-10 0:01 
GeneralRe: LINK : fatal error LNK1104: cannot open file 'MyCplusplusWithSTL.lib' after converting VS2008 to VS2010 Pin
Chesnokov Yuriy10-Aug-10 0:17
professionalChesnokov Yuriy10-Aug-10 0:17 
GeneralRe: LINK : fatal error LNK1104: cannot open file 'MyCplusplusWithSTL.lib' after converting VS2008 to VS2010 Pin
Richard MacCutchan10-Aug-10 0:46
mveRichard MacCutchan10-Aug-10 0:46 
GeneralRe: LINK : fatal error LNK1104: cannot open file 'MyCplusplusWithSTL.lib' after converting VS2008 to VS2010 Pin
Chesnokov Yuriy10-Aug-10 0:56
professionalChesnokov Yuriy10-Aug-10 0:56 
GeneralRe: LINK : fatal error LNK1104: cannot open file 'MyCplusplusWithSTL.lib' after converting VS2008 to VS2010 Pin
Richard MacCutchan10-Aug-10 1:40
mveRichard MacCutchan10-Aug-10 1:40 
Questionshell32.dll Pin
dilara semerci9-Aug-10 22:27
dilara semerci9-Aug-10 22:27 
AnswerRe: shell32.dll Pin
«_Superman_»9-Aug-10 22:37
professional«_Superman_»9-Aug-10 22:37 
AnswerRe: shell32.dll Pin
ThatsAlok9-Aug-10 22:45
ThatsAlok9-Aug-10 22:45 

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.