double * func()
{
vector<double> vec;
return vec;
}
I don't think there is a typecast for double to vector. What you should do is use a pointer to a vector variable:
vector<double> * func()
{
vector<double> vec;
return vec;
}
That should work, but no guarantees since I didn't test it. Also, you may wish to change your double pointer in main() to a pointer to vector.
Now, if you are trying to use the pointer to double for data in the vector, you may wish to just use an iterator.
marinme
Junior Poster in Training
63 posts since Apr 2005
Reputation Points: 10
Solved Threads: 1
It should work just using
p = &vec_account;
marinme
Junior Poster in Training
63 posts since Apr 2005
Reputation Points: 10
Solved Threads: 1
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
vector<double> *func()
{
static const double init[] = {1.0,1.5,2.0,3.3};
vector<double> *vec = new vector<double>(init, init + sizeof init / sizeof *init);
return vec;
}
int main()
{
vector<double> *p = func();
copy(p->begin(), p->end(), ostream_iterator<double>(cout, "\n"));
return 0;
}
/* my output
1
1.5
2
3.3
*/
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314