Implement derived copy and move constructor for std::string?

穿精又带淫゛_ 提交于 2019-12-10 19:17:06

问题


I'm trying to compile the VTK (7.0) library using Embarcaderos clang 32bit compiler.

However, I get a link error at the end that looks like this:

[ 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

The vtkStdString class derives from std::string and is quite simple

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(); }
};

Not totally familiar with cxx11(?) I do believe that the unresolved functions referred to above, in the linker error message, are called the move constructor and move assignment operator.

Trying to naively adding them to the vtkStdString class, using the following code

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

gives the following compile errors (trimmed down to show the important stuff):

In file included from vtkAbstractArray.cxx:31:
vtkStringArray.h:154:23: error: object of type 'vtkStdString' cannot be assigned because its copy assignment operator is implicitly deleted
    { this->Array[id] = value; this->DataChanged(); }
                      ^
vtkStdString.h:56:19: note: copy assignment operator is implicitly deleted because 'vtkStdString' has a user-declared move constructor
    vtkStdString::vtkStdString(vtkStdString&& s)
                  ^
vtkAbstractArray.cxx:391:21: error: call to implicitly-deleted copy constructor of 'vtkStdString'
  return vtkVariant(arr[index]);

Any ideas on how to get past this one?

As VTK is a pretty large library, changing the design of the class vtkStdString is not an option.

来源:https://stackoverflow.com/questions/51690774/implement-derived-copy-and-move-constructor-for-stdstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!