S
shuisheng
Dear All,
I have a question. Assume
#include <vector>
using namespace std;
class A
{
private:
vector<int> v;
int n;
public:
void Reset(int i)
{
n = i;
v.resize(i);
}
vector<int>& Vector()
{
return v;
}
};
For class A, 'n' and the size of 'v' must be always consistent. Every
time n is changed, v is reset with the size n. If n is not changed,
the vector v's size can not change, but its values can change, such as
A::Vector()[2] = 3;
But user can use A::Vector().resize() to change the size of the
vector. How can I avoid it and still keep all the std::vector 's
functions to change the values?
Thanks and best regards,
Shuisheng
I have a question. Assume
#include <vector>
using namespace std;
class A
{
private:
vector<int> v;
int n;
public:
void Reset(int i)
{
n = i;
v.resize(i);
}
vector<int>& Vector()
{
return v;
}
};
For class A, 'n' and the size of 'v' must be always consistent. Every
time n is changed, v is reset with the size n. If n is not changed,
the vector v's size can not change, but its values can change, such as
A::Vector()[2] = 3;
But user can use A::Vector().resize() to change the size of the
vector. How can I avoid it and still keep all the std::vector 's
functions to change the values?
Thanks and best regards,
Shuisheng