Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.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++ 我怎样才能找到副本的来源?_C++_Visual Studio 2012_C++11_Compiler Errors_Unique Ptr - Fatal编程技术网

C++ 我怎样才能找到副本的来源?

C++ 我怎样才能找到副本的来源?,c++,visual-studio-2012,c++11,compiler-errors,unique-ptr,C++,Visual Studio 2012,C++11,Compiler Errors,Unique Ptr,我有一些使用代码的容器,这让我很难过。问题是我想在其中一个子字段中放置一个智能指针(unique_ptr)。例如: struct subrecord { int id; int handle; std::list<std::unique_ptr<some_really_big_record>> update; // <-- Problem field }; struct database { std::map <std::st

我有一些使用代码的容器,这让我很难过。问题是我想在其中一个子字段中放置一个智能指针(unique_ptr)。例如:

struct subrecord {
    int id;
    int handle;
    std::list<std::unique_ptr<some_really_big_record>> update; // <-- Problem field
};

struct database {
    std::map <std::string, subrecord> name_subrec_map;
    std::vector <std::string> a_names;
    std::vector <std::string> b_names;
};
struct子记录{
int-id;
int句柄;

std::list update;//如果您的代码在某处复制子记录,它可能会隐藏在错误消息中

由于子记录是可移动但不可复制的,您可以将其放入其标题中:

 struct subrecord 
 { 
       // ...

       subrecord( const subrecord & ) = delete;
       subrecord( subrecord&& ) = default;
 };
您甚至可以暂时注释掉列表成员,查看调用此副本时是否出现任何编译器错误

注:

如果编译器不支持delete和default,则将复制构造函数设为私有,但也必须将移动构造函数设为公共

如果这只是查找编译器错误的临时措施,您可以跳过实现它,因为您不关心链接错误。稍后您将删除它,但还必须删除私有副本构造函数


尽管您最好实现它,因为这将暴露代码中任何进一步复制子记录的尝试,而不给任何敢于这样做的人编译器错误消息地狱。

您的编译器给了您一条错误消息,但没有与之配套的行/文件?@T.E.D:行号不在编译器的代码中。查找e file names.unique_ptr不可复制(尽管它是可移动的)。因此,子记录也是不可复制的(但可以移动)。如果您在任何地方复制子记录,则会出现相同的错误。作为测试放置子记录(const subrecord&)=删除;子记录(subrecord&)=default;可能更容易在代码中找到错误then@T.E.D.您确定编译器没有向您显示导致库中出现错误的调用堆栈吗?GCC和Clang将打印类似于“required from…;required from…;”的内容显示标题中的错误是如何到达的,这样您就可以将其追溯到您自己的代码中。如果VC++不这样做,我会感到惊讶。相关行可能不会以“error”OK开头。删除了以前的注释,因为我得到的错误是(正如您所怀疑的)由于没有使移动构造函数可见。奇怪的是,当我这样做时,所有的东西都会编译。就像事实上没有副本一样。这里最合理的解释可能是@borgleader是正确的,我偶然发现了在Ok中提到的编译器错误,这对VC12来说并不奇怪,因为它不完全符合要求,我很高兴不这么做不再使用VS6了。:-)