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

C / C++ / MFC

 
GeneralRe: Correct usage of reinterpret_cast and static_cast Pin
John R. Shaw12-May-07 12:36
John R. Shaw12-May-07 12:36 
GeneralRe: Correct usage of reinterpret_cast and static_cast Pin
bob1697212-May-07 13:20
bob1697212-May-07 13:20 
GeneralRe: Correct usage of reinterpret_cast and static_cast Pin
Stephen Hewitt13-May-07 15:00
Stephen Hewitt13-May-07 15:00 
GeneralRe: Correct usage of reinterpret_cast and static_cast Pin
John R. Shaw14-May-07 15:12
John R. Shaw14-May-07 15:12 
GeneralRe: Correct usage of reinterpret_cast and static_cast Pin
ComplexLifeForm12-May-07 21:11
ComplexLifeForm12-May-07 21:11 
GeneralRe: Correct usage of reinterpret_cast and static_cast Pin
bob1697213-May-07 2:07
bob1697213-May-07 2:07 
AnswerRe: Correct usage of reinterpret_cast and static_cast Pin
Michael Dunn13-May-07 6:24
sitebuilderMichael Dunn13-May-07 6:24 
GeneralRe: Correct usage of reinterpret_cast and static_cast Pin
Stephen Hewitt13-May-07 14:31
Stephen Hewitt13-May-07 14:31 
I never use C-style casts except in low level code (such as code that grovels around in a PE file, for example). The code “noise” you refer is a feature and something which, in my opinion, should be embraced rather than shunned. Casts should be both explicit (you cast for many different reasons but they all look the same with C-style casts) and visible (it’s easy to “grep” for C++ style casts and they stick out). The C++ style casts are also safer, for example:
// Console.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include <iostream>
 
using namespace std;
 
class NoClassesDeriveFromMe
{
public:
	void Who()
	{
		cout << "NoClassesDeriveFromMe" << endl;
	}
};
 
class BaseClass
{
public:
	void Who()
	{
		cout << "BaseClass" << endl;
	}
};
 
class DerivedClass : public BaseClass
{
public:
	void Who()
	{
		cout << "DerivedClass" << endl;
	}
};
 
int main(int arvc, char* argv[])
{
	NoClassesDeriveFromMe d;
	((DerivedClass&)d).Who();
		// Clearly a coding error but will compile. C-style casts behave like
		// a 'reinterpret_cast' in this case.
 
	static_cast<DerivedClass&>(d).Who();
		// Clearly still an error (the same error) but will not compile.
 
	return 0;
}


Steve

GeneralRe: Correct usage of reinterpret_cast and static_cast Pin
bob1697213-May-07 19:41
bob1697213-May-07 19:41 
GeneralRe: Correct usage of reinterpret_cast and static_cast Pin
Stephen Hewitt13-May-07 19:48
Stephen Hewitt13-May-07 19:48 
GeneralRe: Correct usage of reinterpret_cast and static_cast Pin
Stephen Hewitt13-May-07 16:46
Stephen Hewitt13-May-07 16:46 
AnswerRe: Correct usage of reinterpret_cast and static_cast Pin
Stephen Hewitt13-May-07 15:04
Stephen Hewitt13-May-07 15:04 
QuestionVS build/run problem. [modified] Pin
CodeGoose12-May-07 9:01
CodeGoose12-May-07 9:01 
AnswerRe: VS build/run problem. Pin
Hans Dietrich12-May-07 10:55
mentorHans Dietrich12-May-07 10:55 
GeneralRe: VS build/run problem. Pin
CodeGoose12-May-07 13:31
CodeGoose12-May-07 13:31 
AnswerRe: VS build/run problem. Pin
prasad_som12-May-07 19:33
prasad_som12-May-07 19:33 
AnswerRe: VS build/run problem. Pin
Gary R. Wheeler13-May-07 2:37
Gary R. Wheeler13-May-07 2:37 
Questionsimple question Pin
Dj_Lordas12-May-07 8:26
Dj_Lordas12-May-07 8:26 
AnswerRe: simple question Pin
biswajit nayak12-May-07 8:50
biswajit nayak12-May-07 8:50 
AnswerRe: simple question Pin
John R. Shaw12-May-07 11:27
John R. Shaw12-May-07 11:27 
Questionrelated to vc++ and xml Pin
biswajit nayak12-May-07 8:13
biswajit nayak12-May-07 8:13 
AnswerRe: related to vc++ and xml Pin
CPallini12-May-07 8:21
mveCPallini12-May-07 8:21 
AnswerRe: related to vc++ and xml Pin
Hamid_RT12-May-07 8:26
Hamid_RT12-May-07 8:26 
Questionvc++ related question Pin
biswajit nayak12-May-07 7:46
biswajit nayak12-May-07 7:46 
AnswerRe: vc++ related question Pin
CPallini12-May-07 8:10
mveCPallini12-May-07 8:10 

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.