Click here to Skip to main content
15,916,188 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to get data in a grid control of a property page to another property page Pin
vc++_fragrance17-Jul-06 6:25
vc++_fragrance17-Jul-06 6:25 
QuestionAlways Show Button on Foreground Pin
Vaibhavsh8317-Jul-06 6:24
Vaibhavsh8317-Jul-06 6:24 
AnswerRe: Always Show Button on Foreground Pin
PJ Arends17-Jul-06 19:42
professionalPJ Arends17-Jul-06 19:42 
Questionhow to pass value to MFC exe Pin
maharaja pandian17-Jul-06 6:00
maharaja pandian17-Jul-06 6:00 
AnswerRe: how to pass value to MFC exe Pin
Cedric Moonen17-Jul-06 6:37
Cedric Moonen17-Jul-06 6:37 
GeneralRe: how to pass value to MFC exe Pin
maharaja pandian17-Jul-06 19:26
maharaja pandian17-Jul-06 19:26 
AnswerRe: how to pass value to MFC exe Pin
David Crow17-Jul-06 6:47
David Crow17-Jul-06 6:47 
GeneralRe: how to pass value to MFC exe Pin
maharaja pandian17-Jul-06 19:28
maharaja pandian17-Jul-06 19:28 
QuestionRe: how to pass value to MFC exe Pin
David Crow18-Jul-06 2:36
David Crow18-Jul-06 2:36 
AnswerRe: how to pass value to MFC exe Pin
William.Wang17-Jul-06 16:20
William.Wang17-Jul-06 16:20 
GeneralRe: how to pass value to MFC exe Pin
maharaja pandian17-Jul-06 19:29
maharaja pandian17-Jul-06 19:29 
Questionhow to pass value to MFC exe from a dll Pin
maharaja pandian17-Jul-06 5:59
maharaja pandian17-Jul-06 5:59 
AnswerRe: how to pass value to MFC exe from a dll Pin
led mike17-Jul-06 7:12
led mike17-Jul-06 7:12 
QuestionAnimateWindow with controls on window Pin
hell_admin17-Jul-06 5:11
hell_admin17-Jul-06 5:11 
GeneralC++ style casting Pin
Rob Caldecott17-Jul-06 5:11
Rob Caldecott17-Jul-06 5:11 
GeneralRe: C++ style casting Pin
toxcct17-Jul-06 5:25
toxcct17-Jul-06 5:25 
GeneralRe: C++ style casting Pin
David Crow17-Jul-06 5:25
David Crow17-Jul-06 5:25 
GeneralRe: C++ style casting Pin
Nemanja Trifunovic17-Jul-06 5:35
Nemanja Trifunovic17-Jul-06 5:35 
GeneralRe: C++ style casting Pin
Rob Caldecott17-Jul-06 6:09
Rob Caldecott17-Jul-06 6:09 
GeneralRe: C++ style casting [modified] Pin
ricecake17-Jul-06 11:15
ricecake17-Jul-06 11:15 
GeneralRe: C++ style casting Pin
David Crow17-Jul-06 6:54
David Crow17-Jul-06 6:54 
GeneralRe: C++ style casting Pin
David Crow18-Jul-06 2:48
David Crow18-Jul-06 2:48 
GeneralRe: C++ style casting Pin
Stephen Hewitt17-Jul-06 14:15
Stephen Hewitt17-Jul-06 14:15 
GeneralRe: C++ style casting Pin
David Crow18-Jul-06 2:46
David Crow18-Jul-06 2:46 
GeneralRe: C++ style casting Pin
Stephen Hewitt18-Jul-06 3:58
Stephen Hewitt18-Jul-06 3:58 
C style casts are anything but clear. While C-style casts look simple they are actually very complicated and subtle. In small programs this often goes unnoticed. But as the program gets larger real problems can and do occur. Try this example program. I know it's on the longish side but it's typical of real applications and may suprise you.

The output with the #include is:
Base2

The output without #include is:
Base1

Not many C++ programmers will be able to spot the problem.

--------------------

// Casts.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include "Functions.h"

// C-style casts suck. The program will compile with or without the line below using C-style casts.
// With it all is OK, without it the program misbehaves at runtime. If 'static_cast' is used the
// program not compile without the #include and you don't get any nasty suprises.
#include "Classes.h"

int main(int argc, char* argv[])
{
Derived *pDerived = MakeDerived();
DoStuff((Base2*)pDerived);
//DoStuff(static_cast<Base2*>(pDerived));
KillDerived(pDerived);

return 0;
}

\/\/\/\/\/\/

// Classes.h

#ifndef __CLASSES_H__
#define __CLASSES_H__

class Base1
{
public:
Base1();
void Print() const;

private:
const char *m_pName;
};

class Base2
{
public:
Base2();
void Print() const;

private:
const char *m_pName;
};

class Derived : public Base1, public Base2
{
};

#endif // !__CLASSES_H__

\/\/\/\/\/\/

// Functions.h

#ifndef __FUNCTIONS_H__
#define __FUNCTIONS_H__

class Base1;
class Base2;
class Derived;

Derived* MakeDerived();
void KillDerived(Derived *pDerived);
void DoStuff(Base2 *pB2);

#endif // !__FUNCTIONS_H__

\/\/\/\/\/\/

// Implementation.cpp

#include "stdafx.h"
#include "Functions.h"
#include "Classes.h"
#include <iostream>

Base1::Base1()
{
m_pName = "Base1";
}

void Base1::Print() const
{
using namespace std;;
cout << m_pName << endl;
}

Base2::Base2()
{
m_pName = "Base2";
}

void Base2::Print() const
{
using namespace std;;
cout << m_pName << endl;
}

Derived* MakeDerived()
{
return new Derived;
}

void KillDerived(Derived *pDerived)
{
delete pDerived;
}

void DoStuff(Base2 *pB2)
{
pB2->Print();
}



Steve

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.