Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I've managed to create an object that holds an array (floats) but I wish to return that value back through a function.
here is the code for the object holding the array.
#include "Object.h"
#include <iostream>
#include <string>
#include "Aplist.h"using namespace std;
Object::Object(){
}
Object::Object(float prray[3]){
setDetails(array);
}
void Object::setDetails(float array[3]){
for (int i=0; i<4; i++)
testarray[i]=array[i];
}void Object::Print(){
for (int i=0; i<4; i++)
cout<<testarray[i]<<endl;
}
float Object::getarray(){
return testarray[3];
}
and here is the code that calls the getarray functionvoid Creator::FindObject(){
float hold[3];
hold[3]=aObject->getarray();
for (int j=0; j<3; j++)
cout<<hold[j];
}My problem is that when I copy all 4 items of the array back to where the function was called (to store in the hold[3] array), I would assume I need a loop of some sort to return each item back but i'm not sure how
Thanks

I think that an OO friendly solution would be to change getarray() to:
float Object::getarray(int i){
return testarray[i];
}Then you can use a for loop to process the array contents:
for (int j=0; j<3; j++)
cout<< aObject->getarray(j);
}
The next step would be to have a method that returns the size of the array:for (int j=0; j<aObject->getarraysize(); ++j) {
cout << aObject->getarray(j);
}

![]() |
Web Menu link no workin'
|
Active directory and vbs
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |