bo*******@gmail.com wrote:
Is there any alternative to hiding private members of a class without
using the Pimpl idiom? I know it probably doesn't affect performance
by much (although it would at least slightly), it just seems like such
an ugly hack and it detracts from the readability of the code.
The immediate one in my head is to use pure abstract base class, which
is basically a p-impl hidden behind virtual dispatch mechanism:
class dog_impl;
class dog
{
virtual void bark() const =0;
virtual ~dog(){}
static std::auto_ptr<dogcreate()
{
return std::auto_ptr<dog>(new dog_impl())
}
};
class dog_impl: public dog_impl
{
void bark() const;
~dog_impl();
};
But, on the user's stand point, this design is just not as intuitive to
use as p-impl, for the following reasons:
1) The interface class is a pure abstract class although it portraits a
concrete one and shall be used as a concrete one.
2) The user has to call a factory function to create an instance.
3) Assignment and copying are not easy to implement. In fact, since the
user is only given an effective pointer, any operator overloading will
be unavailable.
4) The concrete class is not readily derivable.
5) The problem complicates exponentially when more classes are derived
from the same base class.
>
Regards,
B.
Regards,
Ben