定义接口类:
class xxx
{
struct Impl; //声明接口类
public:
int GetTime();
~xxx();
static xxx* Instance()
{
static xxx dbc;
return &dbc;
}
private:
std::shared_ptr<Impl> m_impl; //接口类内部指针
xxx();
};
接口实现:
class xxx::Impl
{
public:
int GetTime();
public:
int m_ntime;
};
xxx::xxx() :m_impl(make_shared<Impl>())
{
}
int xxx::GetTime()
{
return m_impl->GetTime();
}
int xxx::Impl::GetTime()
{
return m_ntime;
}
网友评论