Function returning a pointer
Hello...
I am trying to build an array of pointers to classes, and I want to make a function where I will get the last member of the array. Since that member is an pointer to my Object class, the function has to return a pointer. How do I do that.
Also... My object class has 3 derived classes, is there a way I can create an object array, and store the 3 diferent classes in this same array, or do I have to create 3 separate arrays??
Just return a pointer to the type of object.
OBJECT* function()
OBJECT *my_object;
.
.
.
return my_object;
OBJECT* function()
OBJECT *my_object;
.
.
.
return my_object;
quote: Original post by algumacoisaqualquer
Also... My object class has 3 derived classes, is there a way I can create an object array, and store the 3 diferent classes in this same array, or do I have to create 3 separate arrays??
Yes you can store objects of any classes dirived from the same base class in the same array.
The difference between us and a computer is that, the computer is blindingly stupid, but it is capable of being stupid many, many million times a second.
-Douglas Adams
The difference between us and a computer is that, the computer is blindingly stupid, but it is capable of being stupid many, many million times a second.-Douglas Adams
quote: Original post by Slartibartfastm
Yes you can store objects of any classes dirived from the same base class in the same array.
True, but doing so is downright dangerous. Better to use pointers to the objects as the array element and to ensure the base class has a virtual destructor.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement