[gmpi] Re: C++ detail question
- From: Tim Hockin <thockin@xxxxxxxxxx>
- To: gmpi@xxxxxxxxxxxxx
- Date: Wed, 2 Mar 2005 14:04:20 -0800
On Wed, Mar 02, 2005 at 05:00:52PM -0500, Ron Kuper wrote:
> In VC, the compiler barfs on the cfoo1 assignment. No surprise since
> it's a member of CFoo, therefore not visible at global scope.
woops, I mean to say "cfoo->cfoo1 = 12345;", of course.
> The call to cfoo->method2() crashes.
as expected.
> /* defined in C */
> struct Foo
> {
> int foo1;
> int foo2;
> };
>
> /* defined in C++ */
> class CFoo : public Foo
> {
> public:
> int method1(void) { return 0; }
> virtual int method2(void) { return 0; }
> int cfoo1;
> };
>
> void func(struct Foo *foo)
> {
> CFoo* cfoo = static_cast<CFoo*>(foo);
>
> cfoo->method1(); /* safe? */
> cfoo->method2(); /* not safe */
> cfoo1 = 12345; /* not safe */
> }
>
>
> My assumption is that it is safe to call CFoo::method1 because the
> compiler will do static binding. Now, if method1 does something unsafe,
> that's a different story. Assuming method1 is safe internally, is this
> safe to do?
>
> It seems pretty clear that CFoo::method2 is illegal, as the CFoo object
> does not have a valid vtable. Accessing the cfoo1 member is likewise
> bad because it doesn't exist.
>
> The question is whether it is safe to access method1?
>
> Specifically, there is a C struct that I want to wrap in C++, including
> a couple of operator methods (needed to be put into a map). We could
> create a new CFoo and initialize it with the Foo, but it seems like
> there will be a lot of construct/destruct cycles wasted there...
>
>
>
> ----------------------------------------------------------------------
> Generalized Music Plugin Interface (GMPI) public discussion list
> Participation in this list is contingent upon your abiding by the
> following rules: Please stay on topic. You are responsible for your
> own
> words. Please respect your fellow subscribers. Please do not
> redistribute anyone else's words without their permission.
>
> Archive: http://www.freelists.org/archives/gmpi
> Email gmpi-request@xxxxxxxxxxxxx w/ subject "unsubscribe" to unsubscribe
>
>
> ----------------------------------------------------------------------
> Generalized Music Plugin Interface (GMPI) public discussion list
> Participation in this list is contingent upon your abiding by the
> following rules: Please stay on topic. You are responsible for your own
> words. Please respect your fellow subscribers. Please do not
> redistribute anyone else's words without their permission.
>
> Archive: http://www.freelists.org/archives/gmpi
> Email gmpi-request@xxxxxxxxxxxxx w/ subject "unsubscribe" to unsubscribe
>
----------------------------------------------------------------------
Generalized Music Plugin Interface (GMPI) public discussion list
Participation in this list is contingent upon your abiding by the
following rules: Please stay on topic. You are responsible for your own
words. Please respect your fellow subscribers. Please do not
redistribute anyone else's words without their permission.
Archive: http://www.freelists.org/archives/gmpi
Email gmpi-request@xxxxxxxxxxxxx w/ subject "unsubscribe" to unsubscribe
- References:
- [gmpi] Re: C++ detail question
- From: Ron Kuper
Other related posts:
- » [gmpi] C++ detail question
- » [gmpi] Re: C++ detail question
- » [gmpi] Re: C++ detail question
- » [gmpi] Re: C++ detail question
- » [gmpi] Re: C++ detail question
- » [gmpi] Re: C++ detail question
- » [gmpi] Re: C++ detail question
- » [gmpi] Re: C++ detail question
- » [gmpi] Re: C++ detail question
- » [gmpi] Re: C++ detail question
- » [gmpi] Re: C++ detail question
- » [gmpi] Re: C++ detail question
- » [gmpi] Re: C++ detail question
- [gmpi] Re: C++ detail question
- From: Ron Kuper