Friday, 27 September 2013

const parameter vs rvalue parameter pass, when saved internally to the class private variables

const parameter vs rvalue parameter pass, when saved internally to the
class private variables

class A has an object that can be shared, but only internally modified
class A
{
public:
validityClass ** getValidityShared() // I want to make this const
return, not sure how to protect a double pointer const signeture
{
return &validityShared;
}
private:
validityClass * validityShared;
}
class B need an access, read for validations, or B class population
through its constructor
class B
{
B(A & ainst)
{
aValidityShared = ainst.getValidityShared();
}
private:
validityClass ** aValidityShared;/// tried to save it as validityClass
** & aValidityShared but I guess its wrong, even though everything
worked out
}
after B constructor is over, I am no longer need to know anything about A
class!
int main(int argc, char* argv[])
{
A instA;
B(&instA);
return EXIT_SUCCESS;
}
I want B intance to have the A shared variable, but without any extra
resources, so I tried to save it as an rValue.
what do you recommend? (save internally as an rvalue or const (double const))
how is the const protection for a double pointer?
or just never keep it internally saved?
by the way the example is slightly different than what I am using, but it
is the same context
and I am asking this question because I am getting some weird warning:
member initializers forconst char ** classB::xVar`

No comments:

Post a Comment