Quick question about vectors in functions

Hello all,

I'm currently trying to write a program that will be allow the user to muck around with net present value calculations. It's basically an exervise for me to practice encapsulation and object oriented programming.

I am using a class. The class is supposed to accept a vector from the rest of the program and then passes it into the member function. The function then uses the vectors in its calculations is supposed to return the vector at the end of its use.

1) Is there any issue that can spring up from using a vector as an input for a class?
2) Is it proper form or is there a better way to be doing this?

Thank you for your time!
1) Is there any issue that can spring up from using a vector as an input for a class?

Exactly what is that supposed to mean? How is the class supposed to take this input?

2) Is it proper form or is there a better way to be doing this?

It doesn't really sound like a class is what you're looking for, you might be better off with a function.
But that depends on what you're trying to do.
Last edited on
Sorry about the misunderstanding, I was a bit tired when I posted that.

I want to pass a vector into a function (which in turn is in a class). I know well enough how to do this with variables, but I haven't done it before with vectors. Are vectors input into functions the same way as variables or is there a different way that it is done.

Thanks!
Treat vector<T> variable as a class object. Always pass by reference.

To read:
returnType myClass::myFunc(const vector<T>& vect, ...);

To read and modify vect:
returnType myClass::myFunc(vector<T>& vect, ...);

And are you talking a bout std::vector container? O.o
Last edited on
Yes.

Okay, I see. So basically I would pass the vector from the main part of the program into this class object, and then go from there in using it?

You can only pass something to a function, but aside from that, yes.
Topic archived. No new replies allowed.