Excuse me, but I couldn't understand the problem at all. It would be
better if you can provide a sample.
The abstract class can have a constructor, there is no restriction
about it. Interfaces and abstract classes are different, although they
have much in common. Abstract classes can contain data members, can
have virtual methods but those methods are required to be virtual.
However, abstract classes may contain one or more pure virtual methods,
which prevents you to instantiate the class. Therefore, instantiating
Node should be considered, rather than Object.
so,
__gc class Referenced
{
};
__abstract __gc class Obj
{
public:
Obj()
{
}
virtual Obj* cloneObject() = 0; // pure virtual
};
__gc class Node : public Obj
{
public:
virtual Obj* cloneObject()
{
Node* pnode = new Node;
// implementation (perhaps, copying)
return pnode;
}
};
should work fine
WithPit - 27 May 2005 22:08 GMT
The problem is that the managed code is calling the unmanaged code. So for
the referenced class this means that it has an pointer to the unmanaged object
__gc class Referenced
{
unmanagedReferenced* _unmanagedObject;
};
with probaly a constructor, but that doesn't mater. The abstract class
object inheritance from Referenced. Like you say
__abstract __gc class Obj, public Referenced
{
public:
Obj()
{
}
virtual Obj* cloneObject() = 0; // pure virtual
};
And the Node class implements the method cloneObject().
__gc class Node : public Obj
{
public:
virtual Obj* cloneObject()
{
return new Obj(static_cast<unmanagedNode*>_unmanagedobject->cloneObject());
}
};
For this a constructor is needed with has an unmanaged object as argument.
That is not the problem. The point is that the unmanaged object is wrapped
inside the managed object but from the outside you don't know the type
anymore. You create a new Node object inside your example but maybe there are
methods when you don't know the exact return type. Could this not be a
problem for the managed wrapper? Or is this implementation the best? Or see i
things the wrong way.
Bye
WithPit
> Excuse me, but I couldn't understand the problem at all. It would be
> better if you can provide a sample.
[quoted text clipped - 34 lines]
>
> should work fine
WithPit - 27 May 2005 22:19 GMT
I forgot something, because with this implementation the Obj class cannot be
abstract because of the fact that it is now instantiated. I wanted to created
an managed wrapper with the same class structure so that abstract unmanaged
classes are also abstract in the managed wrapper and no objects could be
created of it.
You don't know wat type the unmanaged method returns, you only know the
abstract base type. So my question is, is there an implementation possible
with the use of abstract classes like Obj in this example?
Bye
WithPit
> The problem is that the managed code is calling the unmanaged code. So for
> the referenced class this means that it has an pointer to the unmanaged object
[quoted text clipped - 77 lines]
> >
> > should work fine