Returning a pointer to a vector
Hello,
I have a class which contains a vector. This vector is created in a function called "CreateVector". So far, I have created this vector in this function, and returned the vector as a whole. However, because the vector is large, ideally I'd like to be able to return a pointer to the vector. How can I do this? Can you create a pointer to a vector?
Here is what I have so far:
Code:
#include <vector>
using namespace std;
class My_Class
{
private:
vector<int*> x;
vector<int*> CreateVector()
{
vector<int*> y(100);
for (int i = 0; i < 100; i ++)
{
y[i] = i * i;
}
return y;
};
public:
void SetX()
{
x = CreateVector();
};
};
in main()
{
My_Class my_object;
my_object.SetX();
return 0;
}
(This is just an example piece of code to demonstrate my problem, the actual CreateVector() function does much more than is shown)
What do I need to do so that I can return a pointer to this vector, in order to speed up the program?
Thanks!