chemicalx001
asked on
c++ pointers...
Quick c++ question, possibly an idiotic one...
If i have a function, say:
vector<Point2f> dothings(vector<Point2f> cornerPoints)
{
int 2 = 2;
int 3 = 3;
cornerPoints.push_back(2);
cornerPoints.push_back(3);
}
and i want to call it like this:
dothings(pointArray);
BUT, i to also specify the resulting array. So I pass it 'pointArray', but I want it to give back a NEW array, with the additions from the function.
So i want to say:
dothings(pointArray, newArray);
And newArray will be pointArray, plus the result of the dothings function.
How do i do this? a return? or a pointer?
thanks!
If i have a function, say:
vector<Point2f> dothings(vector<Point2f> cornerPoints)
{
int 2 = 2;
int 3 = 3;
cornerPoints.push_back(2);
cornerPoints.push_back(3);
}
and i want to call it like this:
dothings(pointArray);
BUT, i to also specify the resulting array. So I pass it 'pointArray', but I want it to give back a NEW array, with the additions from the function.
So i want to say:
dothings(pointArray, newArray);
And newArray will be pointArray, plus the result of the dothings function.
How do i do this? a return? or a pointer?
thanks!
vector<Point2f> dothings(vector<Point2f> cornerPoints) {
int 2 = 2;
int 3 = 3
variables in c or c++ may not begin with a digit. the compiler would not be able to distinguish between constants and variables.
vector<Point2f> dothings(vector<Point2f> cornerPoints) {
int x = 2;
int y1 = 3;
Sara
ASKER
thanks Sara, forgive my idiocy, I need to return a different vector than the one that is passed.
Something like:
std::vector<pointf> dothings(const std::vector<pointf> & inparr, vectorThatGetsReturned)
{
std::vector<pointf> arr = inparr;
Tar.push_back(arr[0]);
return Tar;
}
But i need to specify when i pass the vector what BOTH vectors will be.
dothings(array, newArray);
so that I can call the 'Tar' array.
Something like:
std::vector<pointf> dothings(const std::vector<pointf> & inparr, vectorThatGetsReturned)
{
std::vector<pointf> arr = inparr;
Tar.push_back(arr[0]);
return Tar;
}
But i need to specify when i pass the vector what BOTH vectors will be.
dothings(array, newArray);
so that I can call the 'Tar' array.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok! I think i got it. many thanks Sara.
Open in new window
alternatively you would pass the input array as const std::vector<pointf> & and return a new array by value.
Open in new window
you would do the second if the arrays are small (say less than 100 points) and if the input array might be preserved by the caller.
Sara