Click here to Skip to main content
15,887,485 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C++ style casting Pin
Maximilien17-Jul-06 6:31
Maximilien17-Jul-06 6:31 
GeneralRe: C++ style casting Pin
David Crow17-Jul-06 6:51
David Crow17-Jul-06 6:51 
GeneralRe: C++ style casting Pin
Jörgen Sigvardsson17-Jul-06 9:03
Jörgen Sigvardsson17-Jul-06 9:03 
GeneralRe: C++ style casting Pin
Zac Howland17-Jul-06 9:49
Zac Howland17-Jul-06 9:49 
GeneralRe: C++ style casting Pin
Stephen Hewitt17-Jul-06 14:16
Stephen Hewitt17-Jul-06 14:16 
GeneralRe: C++ style casting Pin
Zac Howland17-Jul-06 16:06
Zac Howland17-Jul-06 16:06 
GeneralRe: C++ style casting [modified] Pin
Jörgen Sigvardsson17-Jul-06 15:13
Jörgen Sigvardsson17-Jul-06 15:13 
GeneralRe: C++ style casting Pin
Zac Howland17-Jul-06 16:12
Zac Howland17-Jul-06 16:12 
Jörgen Sigvardsson wrote:
In essence, I only to constructor like casts when dealing with integral types.


I have used these types of casts for integral types myself; however, I tend to look at them more as constructors instead of casts. For example:

long l = 1234L;
short s = (short)l;


Is really just creating a short by "passing" a long into an implicitly overriden constructor. It is easier to see if you view it as objects instead of primitive types. In that sense, I agree with you, but I still use caution when doing it for one simple reason: many beginning programmers tend to be lazy and see the above code and think nothing of extending it to do the following:

class A {};

class B : public A {};

B b;
B* pB = &b;
A* pA = (A*)pB;


Which while safe in this example, can get much more complex with a different inheritance model.

If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac
GeneralRe: C++ style casting Pin
Zac Howland17-Jul-06 9:46
Zac Howland17-Jul-06 9:46 
QuestionBackground color Pin
goodoljosh198017-Jul-06 5:06
goodoljosh198017-Jul-06 5:06 
AnswerRe: Background color Pin
SimonSays17-Jul-06 6:05
SimonSays17-Jul-06 6:05 
GeneralRe: Background color Pin
goodoljosh198017-Jul-06 9:14
goodoljosh198017-Jul-06 9:14 
AnswerRe: Background color Pin
Hamid_RT17-Jul-06 18:14
Hamid_RT17-Jul-06 18:14 
QuestionExporting function objects from DLL Pin
napoleaninlondon17-Jul-06 4:52
napoleaninlondon17-Jul-06 4:52 
AnswerRe: Exporting function objects from DLL Pin
Cedric Moonen17-Jul-06 4:57
Cedric Moonen17-Jul-06 4:57 
GeneralRe: Exporting function objects from DLL Pin
napoleaninlondon17-Jul-06 5:04
napoleaninlondon17-Jul-06 5:04 
GeneralRe: Exporting function objects from DLL Pin
Cedric Moonen17-Jul-06 5:10
Cedric Moonen17-Jul-06 5:10 
GeneralRe: Exporting function objects from DLL Pin
napoleaninlondon17-Jul-06 5:18
napoleaninlondon17-Jul-06 5:18 
GeneralOT Pin
Eytukan17-Jul-06 6:25
Eytukan17-Jul-06 6:25 
GeneralRe: OT Pin
Cedric Moonen17-Jul-06 6:32
Cedric Moonen17-Jul-06 6:32 
GeneralRe: OT Pin
Eytukan17-Jul-06 7:11
Eytukan17-Jul-06 7:11 
GeneralHello Pin
Hamid_RT17-Jul-06 7:58
Hamid_RT17-Jul-06 7:58 
QuestionCrash after sending custom message (only in release mode) Pin
Matthijs Wessels17-Jul-06 4:47
Matthijs Wessels17-Jul-06 4:47 
QuestionRe: Crash after sending custom message (only in release mode) Pin
David Crow17-Jul-06 4:52
David Crow17-Jul-06 4:52 
AnswerRe: Crash after sending custom message (only in release mode) [modified] Pin
Matthijs Wessels17-Jul-06 5:01
Matthijs Wessels17-Jul-06 5:01 

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.