you can do this with pointer's, but then you need to add the pointers when you call the function, like:
CODE
#include <iostream>
using namespace std;
void addone(int *, int * );
int main()
{
int a=5;
int b=9;
cout << "a: " << a << " b: " << b << "\n";
addone(&a, &b);
cout << "a: " << a << " b: " << b << "\n";
system("pause");
}
void addone(int *first, int *second)
{
(*first)+=1;
(*second)+=1;
}
You can use a struct like:
CODE
#include <iostream>
using namespace std;
struct two
{
int a;
int b;
};
two func()
{
two temp = {5,4};
return temp;
}
int main()
{
two test = func();
cout << test.a << " " << test.b << "\n";
}
or you can use a vector. the advantice of this is that you dont need to know how manny variables you are going to return.
like:(C++ only)
CODE
#include <iostream>
#include <vector>
using namespace std;
vector<int> fillvec(int a)
{
vector<int> temp;
for (int i=0; i<a; i++)
{
temp.push_back(i);
}
return temp;
}
int main()
{
vector<int> temp;
temp = fillvec(5);
for(int i=0; i<temp.size(); i++)
{
cout << temp[i] << "\n";
}
}
Zy
This post has been edited by zyruz: 20 Jul, 2007 - 12:33 AM