Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 编译器赢得';t让我返回rapidxml::xml_文档,并在头文件中报告错误_C++_Rapidxml - Fatal编程技术网

C++ 编译器赢得';t让我返回rapidxml::xml_文档,并在头文件中报告错误

C++ 编译器赢得';t让我返回rapidxml::xml_文档,并在头文件中报告错误,c++,rapidxml,C++,Rapidxml,编译我的三个文件程序(main.cpp、source.cpp、header.hpp)会生成以下错误: source.cpp: In member function ‘rapidxml::xml_document<> MyClass::generate_xml_document()’: source.cpp:559:9: error: use of deleted function ‘rapidxml::xml_document<>::xml_document(const

编译我的三个文件程序(main.cpp、source.cpp、header.hpp)会生成以下错误:

source.cpp: In member function ‘rapidxml::xml_document<> MyClass::generate_xml_document()’:
source.cpp:559:9: error: use of deleted function ‘rapidxml::xml_document<>::xml_document(const rapidxml::xml_document<>&)’
In file included from header.hpp:12:0,
                 from source.cpp:11:
rapidxml.hpp:1358:11: error: ‘rapidxml::xml_document<>::xml_document(const rapidxml::xml_document<>&)’ is implicitly deleted because the default definition would be ill-formed:
rapidxml.hpp:1322:9: error: ‘rapidxml::xml_node<Ch>::xml_node(const rapidxml::xml_node<Ch>&) [with Ch = char, rapidxml::xml_node<Ch> = rapidxml::xml_node<char>]’ is private
  • rapidxml.hpp:1358是类
    xml\u文档
    类xml\u文档:公共xml\u节点,公共内存池

  • 这是rapidxml中的错误吗?(我很确定不是,因为Marcin Kalicinski绝对是一个比我更好的程序员。)

    基本上,RapidXML
    xml\u文档类型是不可复制的。正如您发布的代码段所示(注释“No copy”暗示),复制构造函数和赋值运算符是私有的,用于强制编译器出错

    您应该在函数中动态创建一个指针,并返回一个指针,或者让函数将对现有
    xml\u文档的引用作为输入

    所以不是这个

    xml_document myFunc() 
    { 
      xml_document doc;
      ...
      return doc; 
    }
    
    xml_document d = myfunc();
    
    你需要这个

    void myFunc(xml_document &doc) 
    {
      ... 
    }
    
    xml_document d;
    myfunc(d);
    
    或者,使用动态分配:

    xml_document *myFunc() 
    { 
      xml_document *doc = new xml_document();
      return doc; 
    }
    
    xml_document d = myfunc();
    ...
    delete d;
    

    后者显然需要智能指针,但这说明了这一点。

    我不知道rapidxml,但我说您不能复制它。您需要通过引用或指针传递它
    xml_document *myFunc() 
    { 
      xml_document *doc = new xml_document();
      return doc; 
    }
    
    xml_document d = myfunc();
    ...
    delete d;