2015-03-31 85 views
0

rapidjson::Document副本结果链接错误:复制rapidjson :: Document时为什么链接器错误但不编译错误?

Error 5 error LNK2019: unresolved external symbol "private: __thiscall rapidjson::GenericValue,class rapidjson::MemoryPoolAllocator >::GenericValue,class rapidjson::MemoryPoolAllocator >(class rapidjson::GenericValue,class rapidjson::MemoryPoolAllocator > const &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@[email protected]@@Z) referenced in function "public: __thiscall rapidjson::GenericDocument,class rapidjson::MemoryPoolAllocator >::GenericDocument,class rapidjson::MemoryPoolAllocator >(class rapidjson::GenericDocument,class rapidjson::MemoryPoolAllocator > const &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@[email protected]@@Z) C:\Layer.obj

我看到rapidjson::Documentrapidjson::GenericValue 一个孩子不具有一个拷贝构造函数:

//! Copy constructor is not permitted. 
private: 
    GenericValue(const GenericValue& rhs); 

我不知道为什么没有编译器错误,但链接器错误? C++试图做什么?

我使用MVC 2013和rapidjson 0.11。这里也有类似的主题:

  1. LNK2019: "Unresolved external symbol" with rapidjson
  2. Rapidjson cannot copy `rapidjson::Document`

回答

1

您已经部分回答了自己的问题:

//! Copy constructor is not permitted. 
private: 
    GenericValue(const GenericValue& rhs); 

类都隐式的拷贝构造函数: http://en.cppreference.com/w/cpp/language/copy_constructor#Implicitly-declared_copy_constructor

这段代码的作者试图通过声明以禁用隐含的拷贝构造函数没有定义。通过声明,可以编译此代码。没有定义,它不能链接,因此你看到你的错误。

更具体地说,您看到的错误消息翻译如下:“GenericDocument类的隐式复制构造函数调用GenericValue类的隐式复制构造函数。GenericValue类中的复制构造函数声明但不是定义“。你看到的文本是更具体的,但显然难以阅读。

在您的代码中(可能是使用rapidjson的),存在对GenericDocument的复制构造函数的意外或故意的调用,这会导致您的整个问题。就我而言,我将GenericDocument作为参数传递给函数。如果你正在做同样的事情,你应该通过引用传递文档,所以它不会被复制。

0

错误意味着有声明的功能,但谁是没有实现。 所以你必须有一些.h声明一些函数,但没有在Rapidjson的任何地方实现。

+0

但如果复制构造函数是私人的,并没有实现,为什么我不会收到编译错误?这实际上是我的问题。 – Narek 2015-03-31 08:25:12

+0

@Narek可能表示某些类自己的代码使用了复制构造函数。或者一个编译器错误。 – 2015-08-06 23:21:30