S
shuisheng
Dear All,
I have a question. Assume
struct A
{
int *p, *q;
};
struct B
{
A a;
const struct& GetA() const
{
return a;
}
};
I hope B::GetA() cannot change p, q pointed values, but it can, such
as
*(B::GetA().p) = 3;
How can I make it really constant? One way may be defining p and q as
follows
const int * p;
const int * q;
Whenever p, q pointed values want to change in class/struct A, do the
const_cast. But this is too cumbersome.
I remember a constant std::vector cannot change its values, even
thought it is also implemented by a inner pointer. How does
std::vector make the values constant?
Thanks and best regards,
Shuisheng
I have a question. Assume
struct A
{
int *p, *q;
};
struct B
{
A a;
const struct& GetA() const
{
return a;
}
};
I hope B::GetA() cannot change p, q pointed values, but it can, such
as
*(B::GetA().p) = 3;
How can I make it really constant? One way may be defining p and q as
follows
const int * p;
const int * q;
Whenever p, q pointed values want to change in class/struct A, do the
const_cast. But this is too cumbersome.
I remember a constant std::vector cannot change its values, even
thought it is also implemented by a inner pointer. How does
std::vector make the values constant?
Thanks and best regards,
Shuisheng