定义接口类及接口类实现

定义接口类:

class xxx

{

struct Impl;  //声明接口类

public:

int GetTime();

~xxx();

static xxx* Instance()

{

static xxx dbc;

return &dbc;

}

private:

std::shared_ptr m_impl;    //接口类内部指针

xxx();

};

接口实现:

class xxx::Impl

{

public:

int GetTime();

public:

int m_ntime;

};

xxx::xxx() :m_impl(make_shared())

{

}

int xxx::GetTime()

{

return m_impl->GetTime();

}

int xxx::Impl::GetTime()

{

return m_ntime;

}

你可能感兴趣的:(定义接口类及接口类实现)