gpt4 book ai didi

c++ - 如何在 Visual Studio 2015 中构建 log4cxx

转载 作者:搜寻专家 更新时间:2023-10-31 02:21:13 24 4
gpt4 key购买 nike

我一直在使用 log4cxx,它可以满足我的需求。我们正在迁移到 VS 2015,我发现当我尝试重建 log4cxx 0.10.0.1 时,Visual Studio 2015 中的编译器会抛出错误。如果我将项目工具集更改为 Visual Studio 2013 (v120),构建仍然有效,但是当我尝试使用它时,它在运行时出现问题。
请参阅下面多次出现的错误消息。有没有人找到使用 Visual Studio 2015 正确构建 log4cxx 的方法?

4>..\..\Log4cxx\log4cxx\apache-log4cxx-0.10.0\src\main\include\log4cxx/layout.h(90): error C2248: 'log4cxx::helpers::ObjectImpl::ObjectImpl': cannot access private member declared in class 'log4cxx::helpers::ObjectImpl'
4>..\..\Log4cxx\log4cxx\apache-log4cxx-0.10.0\src\main\include\log4cxx/helpers/objectimpl.h(43): note: see declaration of 'log4cxx::helpers::ObjectImpl::ObjectImpl'
4>..\..\SDKS\Log4cxx\log4cxx\apache-log4cxx-0.10.0\src\main\include\log4cxx/helpers/objectimpl.h(28): note: see declaration of 'log4cxx::helpers::ObjectImpl'
4>..\..\SDKS\Log4cxx\log4cxx\apache-log4cxx-0.10.0\src\main\include\log4cxx/layout.h(90): note: This diagnostic occurred in the compiler generated function 'log4cxx::Layout::Layout(const log4cxx::Layout &)'

最佳答案

我遇到了同样的问题,希望能找到解决方法。

问题是基类ObjectImpl的定义:

    class LOG4CXX_EXPORT ObjectImpl : public virtual Object
{
public:
ObjectImpl();
virtual ~ObjectImpl();
void addRef() const;
void releaseRef() const;

protected:
mutable unsigned int volatile ref;

private:
//
// prevent object copy and assignment
//
ObjectImpl(const ObjectImpl&);
ObjectImpl& operator=(const ObjectImpl&);
};

如您所见,该类隐藏了复制构造函数和复制赋值运算符,因为使用引用计数器的设计没有合适的实现。使用共享指针会更好。

新的 STL 实现对其集合类使用移动语义,当没有具有移动语义的复制构造函数和复制赋值运算符时,它必须使用不可用的标准运算符。

为了解决这个问题,我们必须在以下类中添加移动操作符:ObjectImpl、Layout、Filter、PatternConverter、TriggeringPolicy 和 RollingPolicyBase。

这是我对 ObjectImpl 的新实现:

    class LOG4CXX_EXPORT ObjectImpl : public virtual Object
{
public:
ObjectImpl();
virtual ~ObjectImpl();
void addRef() const;
void releaseRef() const;

// added for VS2015
ObjectImpl(ObjectImpl && o)
{
ref = o.ref;
o.ref = 0;
}

ObjectImpl& operator=(ObjectImpl && o)
{
ref = o.ref;
o.ref = 0;

return *this;
}
// -----

protected:
mutable unsigned int volatile ref;

private:
//
// prevent object copy and assignment
//
ObjectImpl(const ObjectImpl&);
ObjectImpl& operator=(const ObjectImpl&);
};

还有一个例子。其余类类似:

    class LOG4CXX_EXPORT Filter : public virtual OptionHandler,
public virtual helpers::ObjectImpl
{
/**
Points to the next filter in the filter chain.
*/
FilterPtr next;
public:
Filter();

// added for VS2015
Filter(Filter && o)
: helpers::ObjectImpl(std::move(o))
, next( o.next )
{ }

Filter& operator=(Filter && o)
{
helpers::ObjectImpl::operator=(std::move(o));
next = o.next;
return *this;
}
// end of added for VS2015

...

希望对您有所帮助。

关于c++ - 如何在 Visual Studio 2015 中构建 log4cxx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31679144/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com