Hi there,
How to set vector size in Class ? I have set vector size at time of daclaration but it does not work. And should we have to deallocate vector memory in destructor ?
#include <iostream>
#include <vector> //included to use vector
using namespace std;
class VectorDemo
{
private:
vector<int> vec(5); //this does not work
public:
VectorDemo()
{
//vec input
for(int index=0; index<vec.size(); index++)
{
cout<<"Enter any integer in vector : "<<flush;
cin >> vec.at(index);
}
}
~VectorDemo(){}
void printVectorValues()
{
cout<<"Vector values : ";
for(int index=0; index<vec.size(); index++)
{
cout<<vec[index] <<" ";
}
}
};
int main()
{
VectorDemo ob;
ob.printVectorValues();
return 0;
}
Anyone please help. Thanks !