实现派生的副本并为std :: string移动构造函数?

时间:2018-08-05 01:35:16

标签: c++ c++11 clang c++builder

我正在尝试使用Embarcaderos clang 32位编译器来编译VTK(7.0)库。

但是,最后我收到一个链接错误,看起来像这样:

scala -version

vtkStdString类是从std :: string派生的,非常简单

[ 56%] Linking CXX shared library ..\..\bin\vtkCommonDataModel-7.0.dll
Embarcadero C++ 7.30 for Win32 Copyright (c) 2012-2017 Embarcadero Technologies, Inc.
bcc32c.exe: warning: argument unused during compilation: '-auto-dependency-output'
bcc32c.exe: warning: argument unused during compilation: '-sys-header-deps'
bcc32c.exe: warning: argument unused during compilation: '-nobuiltininc'
bcc32c.exe: warning: argument unused during compilation: '-Xclang -cxx-abi'
bcc32c.exe: warning: argument unused during compilation: '-Xclang borland'
Turbo Incremental Link 6.90 Copyright (c) 1997-2017 Embarcadero Technologies, Inc.
Error: Unresolved external 'vtkStdString::operator =(vtkStdString&&)' referenced from P:\BUILDS\CLANG32C\VTKFORK-NINJA\COMMON\DATAMODEL\CMAKEFILES\VTKCOMMONDATAMODEL.DIR\VTKDISTRIBUTEDGRAPHHELPER.CXX.OBJ
Error: Unresolved external 'vtkStdString::vtkStdString(vtkStdString&&)' referenced from P:\BUILDS\CLANG32C\VTKFORK-NINJA\COMMON\DATAMODEL\CMAKEFILES\VTKCOMMONDATAMODEL.DIR\VTKDATASETATTRIBUTES.CXX.OBJ
Error: Unable to perform link

我对cxx11(?)并不十分熟悉,但我确实相信链接器错误消息中的上述未解决函数称为move构造函数和move赋值运算符。

尝试使用以下代码将它们天真地添加到vtkStdString类中

class vtkStdString : public std::string
{
public:
  typedef std::string StdString;
  typedef StdString::value_type             value_type;
  typedef StdString::pointer                pointer;
  typedef StdString::reference              reference;
  typedef StdString::const_reference        const_reference;
  typedef StdString::size_type              size_type;
  typedef StdString::difference_type        difference_type;
  typedef StdString::iterator               iterator;
  typedef StdString::const_iterator         const_iterator;
  typedef StdString::reverse_iterator       reverse_iterator;
  typedef StdString::const_reverse_iterator const_reverse_iterator;

  vtkStdString(): StdString() {}
  vtkStdString(const value_type* s): StdString(s) {}
  vtkStdString(const value_type* s, size_type n): StdString(s, n) {}
  vtkStdString(const StdString& s, size_type pos=0, size_type n=npos):
    StdString(s, pos, n) {}
  operator const char *() { return this->c_str(); }
};

给出以下编译错误(整理以显示重要内容):

...
vtkStdString& operator=(vtkStdString&& rhs)
{
    std::string::operator=(std::move(rhs));
    return *this;
}
vtkStdString(vtkStdString&& s)
{//only trying to compile.. not final code! }
...

关于如何克服这一难题的任何想法?

由于VTK是一个相当大的库,因此不能更改类vtkStdString的设计。

0 个答案:

没有答案