Re: Interface to class casts
- From: "Alexander Nickolov" <agnickolov@xxxxxxxx>
- Date: Tue, 16 Jan 2007 10:19:40 -0800
No, you can't assume that. The only somewhat safe way
to assume no proxy is if your interface does not have
marshaling support (e.g. has the [local] attribute). Even
then, you can still get somebody else's implementation
of the same interface and you are again screwed. Don't
follow Brian's advice.
There's a much more elegant solution for your problem.
It's called persistence. Implement the IPersistXXX
interface required by RDB (IPersistStreamInit for
example, but bear in mind I'm not familiar with RDB)
on your object and work directly through it.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://vcfaq.mvps.org
=====================================
"Jack Hughes" <jhughes@xxxxxxxxxxxxxx> wrote in message
news:uw9K7eZOHHA.448@xxxxxxxxxxxxxxxxxxxxxxx
Brian Muth wrote:
"Jack Hughes" <jhughes@xxxxxxxxxxxxxx> wrote in message
news:OPpgxYZOHHA.4848@xxxxxxxxxxxxxxxxxxxxxxx
I have a couple of C++ classes CCar and CWheel implementing the ICar and
IWheel interfaces respectively.
One of ICar methods (and implemented by CCar) is AddWheel(IWheel*
aNewWheel).
One of the problems I have is that I need to access the CWheel class
instead of just going through IWheel for doing RDB persistence. I don't
want to clutter up the IWheel interface with this kind of implementation
detail.
How do I safely go from a IWheel* to the respective CWheel* in the
AddWheel method?
As I understand it, IWheel* is a super class of CWheel so one of the C++
casts should do the job?
If you know for sure that the IWheel* pointer is not pointing to a proxy,
then you can use static_cast<CWheel *>. Do not use reinterpret_cast<>.
Brian
Cheers Brian.
I can assume that I am not using a proxy if I am not using COM+ and I am
not using DCOM? Are there any other circumstances when a proxy is
involved?
Jack
.
- Follow-Ups:
- Re: Interface to class casts
- From: Jack Hughes
- Re: Interface to class casts
- References:
- Interface to class casts
- From: Jack Hughes
- Re: Interface to class casts
- From: Brian Muth
- Re: Interface to class casts
- From: Jack Hughes
- Interface to class casts
- Prev by Date: Re: proxy/stub woes
- Next by Date: Re: Interface to class casts
- Previous by thread: Re: Interface to class casts
- Next by thread: Re: Interface to class casts
- Index(es):
Relevant Pages
|