Re: Copying void *?
On Feb 21, 4:08 pm, Travis <travis.bow...@gmail.com> wrote:
> So I had a Tree (custom written) that had, as a node type, as pretty
> simple class. The class just stored some std::string's plus a void*.
>
> So my tree instantiation use to be Tree <myClass *> myTree so adding a
> new looked something like
>
> myTree.Insert( new myClass( "string 1", "string 2", (void*) 2) ); //
> seemed to work fine
>
> Then I decided it was silly to store a tree of pionters, and changed
> the tree to Tree <myClass> myTree so adding looked more like...
>
> myTree.Insert( myClass( "string 1", "string 2", (void*) 2) ); //
> crashes?
>
> This insertion style compiles but the later one it crashes and I'm not
> sure why. It would *appear* that the void* at some point goes NULL or
> otherwise erroneous.
>
> Just looking for some educated thoughts/opinions. Thanks.
Would have to see the declaration and definition of the constructor
for the object type of myClass to explain what is happening. I
_really_ doubt you want to be passing a void pointer to a constant
integer that will soon be out of scope.
What exactly do you want to use the parameters of the constructor for?
What types will they be?
Where are they stored and how are they used?
While I've found that sometimes using a void pointer is the only
option, it is pretty rare. What made you decide to use a void pointer?
Are all nodes going to be containing different types of objects that
were allocated outside the node?
Or would all nodes contain the same type of objects.
Maybe you want to templatize your node class?
Would need more details as your goal is unknown.
|