M
mliptak
Hi group,
suppose having this code using PIMPL:
// a.hh
class A
{
struct Impl;
public:
A();
int Member1() const
{ return mrMember; }
int Member2() const;
private:
Impl* mpImpl;
int& mrMember;
};
// a.cc
struct A::Impl
{
int mMember;
};
A()
: mpImpl(new Impl)
, mrMember(mpImpl->mMember)
{}
int A::Member2() const
{ return mpImpl->mMember; }
// end of code
The member functions Member1() and Member2() should return the same
value at all times, except for the Member1() operation can be inlined
while Member2() cannot.
Does it make sense for certain members, which are hidden in sturct
Impl, to expose references in the header file so the accessor
operations can be inlined?
Is it better, from the design point of view, to have the member
attribute in class A and have its reference in struct Impl so Impl
functions can access it? (I am assuming from performance point of
view it should be the same as the code above).
Thanks
m.
suppose having this code using PIMPL:
// a.hh
class A
{
struct Impl;
public:
A();
int Member1() const
{ return mrMember; }
int Member2() const;
private:
Impl* mpImpl;
int& mrMember;
};
// a.cc
struct A::Impl
{
int mMember;
};
A()
: mpImpl(new Impl)
, mrMember(mpImpl->mMember)
{}
int A::Member2() const
{ return mpImpl->mMember; }
// end of code
The member functions Member1() and Member2() should return the same
value at all times, except for the Member1() operation can be inlined
while Member2() cannot.
Does it make sense for certain members, which are hidden in sturct
Impl, to expose references in the header file so the accessor
operations can be inlined?
Is it better, from the design point of view, to have the member
attribute in class A and have its reference in struct Impl so Impl
functions can access it? (I am assuming from performance point of
view it should be the same as the code above).
Thanks
m.