【发布时间】:2017-09-21 03:47:10
【问题描述】:
我正在实现一个 c++ 应用程序,除此之外,我还使用 Poco 库。具体来说,我正在尝试使用 poco 日志框架。我创建了一个类,它使用来自 poco 示例之一的以下代码来创建日志记录机制:
AutoPtr<PatternFormatter> pPatternFormatter(new PatternFormatter());
AutoPtr<FormattingChannel>pFormattingChannel(new
FormattingChannel(pPatternFormatter));
pPatternFormatter->setProperty("pattern", "%s: %p : %t");
AutoPtr<ConsoleChannel> pConsoleChannel(new ConsoleChannel());
pFormattingChannel->setChannel(pConsoleChannel);
但是,当我尝试用 poco SharedPtr 指针替换 poco AutoPtr 我收到以下构建错误:
错误 C2248 'Poco::FileChannel::~FileChannel':无法访问在类 'Poco::FileChannel' 中声明的受保护成员
我已经搜索并发现 FileChannel 类的析构函数受保护,我假设使用它是为了防止通过指向其基的指针删除对象。 使用公共或受保护的访问说明符使我的类派生自 FileChannel 以使 SharedPtr 工作或以其他方式工作是否有效?
【问题讨论】:
标签: c++ protected derived-class poco-libraries