I keep getting a Segmentation fault error when i run my program, i read that this is an error with memory or somthing, i was hoping someone could point out where the problem in my program is. My code is below.
#include <iostream>
#include <vector>
using namespace std;
class sequence
{
public:
void read();
int print(vector<int>&) const;
int getelement(sequence x,int i);
sequence();
sequence(int s);
private:
int next;
vector<int> v2;
};
int main(){
sequence x;
x.read();
int element;
int i;
cout << "please enter the element you would like returned." << endl;
cin >> i;
element = x.getelement(x,i);
return 0;
}
sequence :: sequence()
{
}
sequence:: sequence(int s)
{
vector<int> v2(s);
}
void sequence::read()
{
vector<int> v2;
int s;
cout << "Enter the number of integers" << endl;
cin >> s;
cout << "Enter your sequence, place a negative number at end." << endl;
cin >> next;
while(next > 0)
{
v2.push_back(next);
cin >> next;
}
for(unsigned int i = 0; i < v2.size(); i++)
{
cout << v2[i];
}
}
int sequence::print(vector<int>&)const
{
for(unsigned int i = 0; i < v2.size(); i++)
{
cout << v2[i];
}
}
int sequence::getelement(sequence x,int i)
{
int a;
return x.v2[a];
}