我一直在使用log4cxx,它可以满足我的需要。我们将转到VS 2015,我发现Visual 2015中的编译器在我试图重建log4cxx 0.10.0.1时抛出了错误。如果我将项目工具集更改为Visual 2013 (v120),则构建仍然有效,但当我尝试使用它时,在运行时会出现问题。
请参阅下面的错误消息,它会在多个场合发生。有人找到用Visual 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 &)'
发布于 2015-07-30 12:20:31
我也有同样的问题,希望能找到解决办法。
问题是基类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实现对它们的集合类使用了移动语义,当没有带有move语义的复制构造函数和复制赋值操作符时,必须使用标准运算符,这些运算符是不可用的。
为了解决这个问题,我们必须将move操作符添加到以下类: 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
...
我希望这能帮上忙。
发布于 2016-09-23 22:27:17
一位同事遇到了这个问题,他通过选择File
> New
> Project
> Visual C++
并选择Install Windows XP Support for C++
解决了这个问题。奇怪的是,我从来没有这样做过,但我也从来没有遇到过同样的问题。
发布于 2021-12-07 07:20:26
下面的代码是正确的答案apache-log4cxx-0.10.0
vs2015
// objectimpl.h
namespace log4cxx
{
namespace helpers
{
/** Implementation class for Object.*/
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&);
};
}
}
// objectimpl.cpp
ObjectImpl::ObjectImpl(const ObjectImpl& o)
{
ref = o.ref;
o.ref = 0;
}
ObjectImpl& ObjectImpl::operator=(const ObjectImpl& o)
{
ref = o.ref;
o.ref = 0;
return *this;
}
https://stackoverflow.com/questions/31679144
复制相似问题