Click here to Skip to main content
15,915,160 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CFile does not open Pin
Mark Salsbery7-Dec-06 5:44
Mark Salsbery7-Dec-06 5:44 
QuestionTypecasting incompatible types Pin
WillemM7-Dec-06 2:22
WillemM7-Dec-06 2:22 
AnswerRe: Typecasting incompatible types Pin
Mark Salsbery7-Dec-06 5:57
Mark Salsbery7-Dec-06 5:57 
GeneralRe: Typecasting incompatible types Pin
WillemM7-Dec-06 6:26
WillemM7-Dec-06 6:26 
GeneralRe: Typecasting incompatible types Pin
Mark Salsbery7-Dec-06 6:43
Mark Salsbery7-Dec-06 6:43 
GeneralRe: Typecasting incompatible types Pin
WillemM7-Dec-06 6:44
WillemM7-Dec-06 6:44 
GeneralRe: Typecasting incompatible types Pin
Mark Salsbery7-Dec-06 6:51
Mark Salsbery7-Dec-06 6:51 
AnswerRe: Typecasting incompatible types [modified] Pin
Stephen Hewitt7-Dec-06 11:52
Stephen Hewitt7-Dec-06 11:52 
Handle<A> and Handle<B> are distinct types: you can not safely cast between them. Any time you have to use reinterpret_cast or C-style casts (I never use C-style casts and would not allow any in code under my control) alarm bells should ring.

Say we have a template like this:
template <typename T>
class MyTemplate
{
};


Then MyTemplate<int> and MyTemplate<double> are distinct types and not related by inheritence. This is a basic property of C++ templates.

-- modified at 21:30 Thursday 7th December, 2006

Even if the representation happens to be the same an explicit specialisation added later could silently break this assumption. In short, don't be reckless with casting.

Can you elaborate on what you're trying to achieve? Perhaps there is a better type-safe mechanism to achieve it. For example consider the following:

template <typename T>
class MyTemplate
{
public:
    MyTemplate(const T &data);
 
    template <typename O>
    MyTemplate(const MyTemplate<O> &other);
};



Steve

QuestionBackup & Recovery Utility for MS Exchange Pin
Vinay Jain7-Dec-06 2:12
Vinay Jain7-Dec-06 2:12 
Questionhighlight list control items using mouse Pin
YaronNir7-Dec-06 2:06
YaronNir7-Dec-06 2:06 
AnswerRe: highlight list control items using mouse Pin
Sunil P V7-Dec-06 2:28
Sunil P V7-Dec-06 2:28 
Questionload image Pin
Sunil P V7-Dec-06 1:34
Sunil P V7-Dec-06 1:34 
AnswerRe: load image Pin
Hamid_RT7-Dec-06 17:50
Hamid_RT7-Dec-06 17:50 
GeneralRe: load image Pin
Sunil P V7-Dec-06 19:02
Sunil P V7-Dec-06 19:02 
GeneralRe: load image Pin
ThatsAlok7-Dec-06 19:23
ThatsAlok7-Dec-06 19:23 
GeneralRe: load image Pin
Hamid_RT8-Dec-06 1:15
Hamid_RT8-Dec-06 1:15 
QuestionScrolling in a SDI project containing ATL COM Servers Pin
Cyber Friend7-Dec-06 0:58
Cyber Friend7-Dec-06 0:58 
QuestionVC++/MFC Pin
amitmistry_petlad 7-Dec-06 0:18
amitmistry_petlad 7-Dec-06 0:18 
AnswerRe: VC++/MFC Pin
Sunil P V7-Dec-06 1:36
Sunil P V7-Dec-06 1:36 
AnswerRe: VC++/MFC Pin
Sam Hobbs7-Dec-06 2:14
Sam Hobbs7-Dec-06 2:14 
AnswerRe: VC++/MFC Pin
David Crow7-Dec-06 5:23
David Crow7-Dec-06 5:23 
QuestionDLL Search path while debugging Pin
misha_grewal7-Dec-06 0:18
misha_grewal7-Dec-06 0:18 
AnswerRe: DLL Search path while debugging Pin
Naveen7-Dec-06 0:28
Naveen7-Dec-06 0:28 
QuestionUsing managed code in unmanaged class Pin
priyank_ldce7-Dec-06 0:13
priyank_ldce7-Dec-06 0:13 
AnswerRe: Using managed code in unmanaged class Pin
prasad_som7-Dec-06 2:21
prasad_som7-Dec-06 2:21 

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.