From: Jack on
I'm creating an ActiveSync DLL using

* VC++ 7.0 in VS 2003; unmanaged code

* MFC71 with STL

* statically linking MFC

* not using ATL

* ignoring default library msvcrtd.lib

* multiple inheritance

* use multi-byte character set

+++

We created a C++ class hierarchy that is about 3 levels deep with
multiple inheritance. Let's not get into how these classes were
defined, unless of course you think that could be causing the problem
;)

class a;

class b : a;

class c : a;

class d : b, c;

class d objTest;

The Problem:
============

Now, using object "objTest", if I'm in class b's constructor when
"objTest" is being created and I call a method in b to set a value in
b, I can see that value set within b while I'm in the debugger, but by
the time the stack unwinds and I get back to class d while creating
objTest the value I set is b is NULL or set back to its default values.
I've set break points to see if the set methods are being called
multiple times, and they are not.

Now, if I then set the same value from d using the b method, it gets
set properly.

I'm also having a general instability problem when using the STL string
class. After the above happens, I then get errors elsewhere in the
code where STL cannot realloc on a string assignment.

string abc = "hello world";
string def = abc;

can cause a low-level exception that something cannot be resized

Any clues would be appreciated.

From: AliR on
this is one of the problems that come up when you are doing
multi-inheritance.

I am assuming that you are not using virual inheritance. In that case the
constructor for your 'a' class will get called twice, once when the 'b'
class's construtor is getting called , and once when the 'c' class's is
getting called. And if you are changing the value of the member in the
construtor of b then when c gets called, which in turn will call a's then
your value will be overwitten.

Anyway to solve this problem you need to use virtual inheritance.

class a
{
};

class b : virtual public a
{
};

class c : virtual public a
{
};

class d : public b, public c
{
};

AliR.

"Jack" <jsimon_mail(a)yahoo.com> wrote in message
news:1108070964.525146.85450(a)g14g2000cwa.googlegroups.com...
> I'm creating an ActiveSync DLL using
>
> * VC++ 7.0 in VS 2003; unmanaged code
>
> * MFC71 with STL
>
> * statically linking MFC
>
> * not using ATL
>
> * ignoring default library msvcrtd.lib
>
> * multiple inheritance
>
> * use multi-byte character set
>
> +++
>
> We created a C++ class hierarchy that is about 3 levels deep with
> multiple inheritance. Let's not get into how these classes were
> defined, unless of course you think that could be causing the problem
> ;)
>
> class a;
>
> class b : a;
>
> class c : a;
>
> class d : b, c;
>
> class d objTest;
>
> The Problem:
> ============
>
> Now, using object "objTest", if I'm in class b's constructor when
> "objTest" is being created and I call a method in b to set a value in
> b, I can see that value set within b while I'm in the debugger, but by
> the time the stack unwinds and I get back to class d while creating
> objTest the value I set is b is NULL or set back to its default values.
> I've set break points to see if the set methods are being called
> multiple times, and they are not.
>
> Now, if I then set the same value from d using the b method, it gets
> set properly.
>
> I'm also having a general instability problem when using the STL string
> class. After the above happens, I then get errors elsewhere in the
> code where STL cannot realloc on a string assignment.
>
> string abc = "hello world";
> string def = abc;
>
> can cause a low-level exception that something cannot be resized
>
> Any clues would be appreciated.
>


From: Jack on
My error for not stating that. Each base class is defined as "public
virtual". And all of the functions are defined in "class a" like
virtual void SetMyValue(Myvalue *dval) = 0;


class a;


class b : public virtual a;


class c : public virtual a;


class d : public virtual b, public virtual c;


class d objTest;

From: Arnaud Debaene on
Jack wrote:
> I'm creating an ActiveSync DLL using
>
> * VC++ 7.0 in VS 2003; unmanaged code
>
> * MFC71 with STL
>
> * statically linking MFC
>
> * not using ATL
>
> * ignoring default library msvcrtd.lib
>
> * multiple inheritance
>
> * use multi-byte character set
>
> +++
>
> We created a C++ class hierarchy that is about 3 levels deep with
> multiple inheritance. Let's not get into how these classes were
> defined, unless of course you think that could be causing the problem
> ;)
>
> class a;
>
> class b : a;
>
> class c : a;
>
> class d : b, c;
>
> class d objTest;
>
> The Problem:
> ============
>
> Now, using object "objTest", if I'm in class b's constructor when
> "objTest" is being created and I call a method in b to set a value in
> b, I can see that value set within b while I'm in the debugger, but by
> the time the stack unwinds and I get back to class d while creating
> objTest the value I set is b is NULL or set back to its default
> values.
<Note : I put the classes name in capital letters to make for an easier
reading/>

By any chance, is the data you modified in B constructor a member of A? If
so, you must be aware that a D object, as you have defined it, has *two* A
subobjects within it (once brings by B, the other by C). It's what is
classically called a diamond-shaped inheritance. If you want to have only
one A subobject within D, you must use virtual inheritance :

class A {};
class B : virtual public A {};
class C : virtual public A {};
class D : public B, public C {};

Arnaud
MVP - VC


From: Jack on
Class A has no data members.

Class B has the data members whose values are going from being set to
unset. The value I see in the debugger is 0x00000001. And when I try
to use it in my code, it indicates a NULL pointer 0x00000000 access
violation.

> class A {};
> class B : virtual public A {};
> class C : virtual public A {};
> class D : public B, public C {};

That is what I kept originally thinking was the problem. I even
removed the "virtual" from before public B, public C in class D's
definition to make it look just like your above example, and I still
have the problem. My code originally looked like the below.

> class A {};
> class B : virtual public A {};
> class C : virtual public A {};
> class D : virtual public B, virtual public C {};

I'm thinking that I might have a heap or module initialization problem
given all of the different technologies I'm glueing together in a
static linked DLL that is called by ActiveSync.