Is casting ever necessary?
From: Calum (calum.bulk_at_ntlworld.com)
Date: 12/16/03
- Next message: Calum: "Code generation from CASE tools"
- Previous message: Cristiano Sadun: "Re: Why "Abstract Factory" has an abstract in it?"
- Next in thread: Universe: "Re: Is casting ever necessary?"
- Reply: Universe: "Re: Is casting ever necessary?"
- Reply: Daniel T.: "Re: Is casting ever necessary?"
- Reply: Tsolak Petrosian: "Re: Is casting ever necessary?"
- Reply: Dave Harris: "Re: Is casting ever necessary?"
- Reply: Bruno Desthuilliers: "Re: Is casting ever necessary?"
- Reply: H. S. Lahman: "Re: Is casting ever necessary?"
- Reply: Peter Ammon: "Re: Is casting ever necessary?"
- Reply: Uncle Bob (Robert C. Martin): "Re: Is casting ever necessary?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 16 Dec 2003 11:04:11 +0000
I was wondering if "casting" was ever necessary. This example is based
on the Microsoft Foundation Classes:
// Library classes:
class CDocument
{
// Library functionality
};
class CView
{
protected:
CDocument *doc;
// Library functionality
};
// User classes:
class MyDoc : public CDocument
{
public:
int user_data;
};
class MyView : public CView
{
public:
MyDoc *getDocument() { return static_cast<MyDoc*>(doc); }
// Is this ugly?
};
The question is, how do functions in MyView access the document MyDoc,
without making a cast? I just feel that a "cast" is an ugly solution to
this problem. Am I right in thinking that, is there a better solution?
Calum
-- Persistent data in C++: http://visula.org/persist
- Next message: Calum: "Code generation from CASE tools"
- Previous message: Cristiano Sadun: "Re: Why "Abstract Factory" has an abstract in it?"
- Next in thread: Universe: "Re: Is casting ever necessary?"
- Reply: Universe: "Re: Is casting ever necessary?"
- Reply: Daniel T.: "Re: Is casting ever necessary?"
- Reply: Tsolak Petrosian: "Re: Is casting ever necessary?"
- Reply: Dave Harris: "Re: Is casting ever necessary?"
- Reply: Bruno Desthuilliers: "Re: Is casting ever necessary?"
- Reply: H. S. Lahman: "Re: Is casting ever necessary?"
- Reply: Peter Ammon: "Re: Is casting ever necessary?"
- Reply: Uncle Bob (Robert C. Martin): "Re: Is casting ever necessary?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|