Jun 6, 2016 at 12:32pm
I'd like to write a function which returns a vector contains integer values
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include <iostream>
#include <vector>
using namespace std;
vector<int>* myVector(int);
int main()
{
int n;
vector<int>* myConversionVector;
cout<<"Please Enter A Number:"<<endl;
cin>>n;
cout<<endl;
myConversionVector=myVector(n);
for (int i=0; i<myConversionVector.size();i++)
{
cout<<myConversionVector[i]<<endl;
}
return 0;
}
vector<int>* myVector(int number)
{
unsigned int remainder=0;
unsigned int division=10;
vector<int>* residual;
while (division!=0)
{
division=number/10;
remainder=number%10;
residual .push_back(remainder);
number=division;
}
return residual;
}
|
But this code does not work and I get the following error message:
|
error: request for member ‘push_back’ in ‘residual’, which is of pointer type ‘std::vector<int>*’ (maybe you meant to use ‘->’ ?)
|
any suggestion how to fix the problem?
Last edited on Jun 6, 2016 at 12:41pm
Jun 6, 2016 at 1:16pm
Why did you define your vector instance as a pointer? I'd start by just getting rid of the pointer (everywhere) and see if that works.