M
Morgan Cheng
Once upon a time, I feel upset about private data member in class header
files, because it expose private data structure of the class. What's
more, if I change some non-static private data member, component using
my class has to be re-compiled.
Recently, I saw some code written by others. The code encapsulate all
private data member into a struct. So, in header file, only forward
declaraction of the struct is needed.
struct FooPrivate;
class Foo
{
public:
...
private:
FooPrivate fooData;
};
In the cpp file of the class, the struct is defined. So, the
implementation of Foo is totally invisible to users. And, change of
private data structure will not affect others.
I think this idea is perfect. What do you think?
files, because it expose private data structure of the class. What's
more, if I change some non-static private data member, component using
my class has to be re-compiled.
Recently, I saw some code written by others. The code encapsulate all
private data member into a struct. So, in header file, only forward
declaraction of the struct is needed.
struct FooPrivate;
class Foo
{
public:
...
private:
FooPrivate fooData;
};
In the cpp file of the class, the struct is defined. So, the
implementation of Foo is totally invisible to users. And, change of
private data structure will not affect others.
I think this idea is perfect. What do you think?