关于effective c++中用句柄类降低编译依赖型,百思不得其解
比如。
Person类用句柄类
Person.h
#ifndef PERSON_H
#define PERSON_H
class Mystring;
class PersonImpl;
class Person
{
public:
Person();
Mystring name() const;
private:
PersonImpl *impl;
};
#endif
------------------------------------
PersonImple.h
#ifndef PERSONIMPL_H
#define PERSONIMPL_H
class Mystring;
class PersonImpl
{
public:
Mystring name() const;
private:
Mystring name_;
};
#endif
------------------------------------
PersonImple.cpp
#include "String.h"
#include "PersonImpl.h"
Mystring PersonImpl::name() const
{
return name_;
}
------------------------------------
String.h
#ifndef STRING_H
#define STRING_H
class Mystring
{
public:
Mystring();
};
#endif
这是不是就是作者所说的意思呢。可是我如果使用Person类还是会报出编译错误,说没有定义Mystring类啊。
因为Person类的实现cpp依然要include PersonImpl.h,依然需要知道Mystring类啊。