So, i declare an array and then just return a pointer to the array and use a counter to display/use the data in the array.
how will te code look like ? something like return *pi;??
Printable View
So, i declare an array and then just return a pointer to the array and use a counter to display/use the data in the array.
how will te code look like ? something like return *pi;??
If you use grumpy's code.. itd be like this (and of course you could pass parameters to aFunction instead):
Looking at that makes me cry.. it looks like such an inefficient method, but then again its late and I've never tried anything like that before.. I'll see in the morning if I can come up with any better ideas for passing lists, for own benefit.Code:#include <iostream>
using namespace std;
struct theStruct
{
int a,b,c,d;
};
theStruct aFunction();
int main()
{
theStruct anObject;
anObject = aFunction();
cout << anObject.a << endl;
cout << anObject.b << endl;
cout << anObject.c << endl;
cin.get();
}
theStruct aFunction()
{
theStruct theObject;
theObject.a = 1;
theObject.b = 2;
theObject.c = 3;
theObject.d = 4;
return theObject;
}
Looking at it it looks like I should return a pointer and make it = new theObject, but I cant think of how I'd recieve it.. its too late, hope it gives you something to work with.
I actually understand it! Thanks