Re: Copying void *?
On Feb 21, 4:43 pm, Travis <travis.bow...@gmail.com> wrote:
> So the constuctor is basically
>
> myClass::myClass (const myClass &rhs)
> {
> string1 = rhs.string1;
> string2 = rhs.string2;
> voidstar = rhs.voidstar;
>
> }
>
> dangerous?
>
> what I want is to have people be able to insert into the tree and
> throw whatever type they want into the tree and i'll store it as a
> void *.
Very dangerous in my opinion:
Who allocates what void * is pointing to?
Who releases it?
If every node may contain a different type, how is the user of the
node going to know what type it contains, perform the proper cast and
use it?
I am still unclear if you want to make a tree that may contain nodes
that contain any _one_ type
i.e
I can make a tree<int> that contains node<int> objects, which contain
ints
I can create another instance of the tree, tree<myclass>, that
contains node<myclass> objects, which that contain myclass
....
or
....
If you are wanting to create a tree that may contain nodes that may
contain any type
i.e.
I can make a tree, that contains one node, that contains an int
The same instance of the tree may contain another node, which contains
a myclass object
The first can be easily done with templates and I can envision it
easily.
The second is harder, and I _think_ it can also be done with
templates, however, I cannot easily envision its design.
I think there is also a boost container type that supports elements of
varying types, such that one element can contain an int while another
element can contain a myclass, with both elements belonging to the
same container.
I think your use of the void * is a way for you to get around a design
problem. But it if isn't a problem in your design, we still need to
see the constructor that takes 3 arguments, allocation of the memory
void * points to, where it is release, and where it is casted and
used.
|