C++ c+中的bug+-在c和x2B中设置U差+;不返回std::copy
我有如下代码:C++ c+中的bug+-在c和x2B中设置U差+;不返回std::copy,c++,stl,set-difference,C++,Stl,Set Difference,我有如下代码: typedef std::set<std::string> set_of_strings; set_of_strings s1, s2, result1; some_func() { s1.insert("1-2"); s1.insert("1-1"); s1.insert("3-4"); s2.insert("1-2");
typedef std::set<std::string> set_of_strings;
set_of_strings s1, s2, result1;
some_func()
{
s1.insert("1-2");
s1.insert("1-1");
s1.insert("3-4");
s2.insert("1-2");
s2.insert("1-3");
s2.insert("3-4");
set_of_strings::iterator s1_begin = s1.begin();
set_of_strings::iterator s1_end = s1.end();
set_of_strings::iterator s2_begin = s2.begin();
set_of_strings::iterator s2_end = s2.end();
set_of_strings::iterator result_begin = result1.begin();
td::insert_iterator<set_of_strings> result_inserter = std::inserter(result1, result_begin);
set_difference(s1_begin, s1_end,s2_begin, s2_end,result_inserter); //This is the problem line
}
{
using namespace std;
set_difference(s1_begin, s1_end,s2_begin, s2_end,result_inserter);
}
如果是std::copy
,则不会有任何问题
我试着把我的陈述放在下面这样的块中:
typedef std::set<std::string> set_of_strings;
set_of_strings s1, s2, result1;
some_func()
{
s1.insert("1-2");
s1.insert("1-1");
s1.insert("3-4");
s2.insert("1-2");
s2.insert("1-3");
s2.insert("3-4");
set_of_strings::iterator s1_begin = s1.begin();
set_of_strings::iterator s1_end = s1.end();
set_of_strings::iterator s2_begin = s2.begin();
set_of_strings::iterator s2_end = s2.end();
set_of_strings::iterator result_begin = result1.begin();
td::insert_iterator<set_of_strings> result_inserter = std::inserter(result1, result_begin);
set_difference(s1_begin, s1_end,s2_begin, s2_end,result_inserter); //This is the problem line
}
{
using namespace std;
set_difference(s1_begin, s1_end,s2_begin, s2_end,result_inserter);
}
但这不起作用。
我知道问题在于我们为自己的目的编写的copy函数,它在许多地方都被使用。这里我想使用std::copy
。
任何人都可以提供帮助。如果您编写了自己的复制函数,编译器可以在与
std::copy
相同的范围内看到它,并且它是一个可能的候选函数,那么一定会导致歧义
没有什么神奇的标志可以让它使用
std::copy
,但我认为如果你把自己的副本放在一个名称空间中,而不使用该名称空间,编译器将无法找到它并返回到std::copy
。也就是说,我不认为我能理解这样一种情况,即您希望创建一个适用于集合迭代器的备用副本
,如果你写了一个泛型函数,它可能不应该被称为copy,因为它会导致像这样的歧义错误。如果你写了自己的copy函数,编译器可以在与std::copy
相同的范围内看到它,并且它是一个可能的候选函数,那么肯定会导致歧义
没有什么神奇的标志可以让它使用std::copy
,但我认为如果你把自己的副本放在一个名称空间中,而不使用该名称空间,编译器将无法找到它并返回到std::copy
。这就是说,我不认为我能理解这样一种情况,即您想要创建一个适用于集合迭代器的备用副本,如果您编写了一个通用副本,它可能不应该被称为copy,因为它会导致像这样的歧义错误。。所以问题在于你没有显示的代码。什么是字符串集
,s1
,s2
,result1
和td:
?完整的错误消息是什么?那么set\u差异
是在std
名称空间中定义的,它还应该使用std::copy
。你能编译吗?它显示了什么?你能在不同的命名空间中移动你自己的代码>拷贝<代码>吗?类型在C++中是很重要的。您正在谈论的对象中有一半的对象我们不知道其类型。@ybungalobill。我刚刚给出了部分代码。复制函数是在我们的核心应用程序中定义的。我只知道我面临的问题。但我无法找到解决我的问题的方法。在这里,类型并不像我向您解释的那样重要。我相信设置差异应该是明确的,并使用std::copy
。与交换
和运算符不同。所以问题在于你没有显示的代码。什么是字符串集
,s1
,s2
,result1
和td:
?完整的错误消息是什么?那么set\u差异
是在std
名称空间中定义的,它还应该使用std::copy
。你能编译吗?它显示了什么?你能在不同的命名空间中移动你自己的代码>拷贝<代码>吗?类型在C++中是很重要的。您正在谈论的对象中有一半的对象我们不知道其类型。@ybungalobill。我刚刚给出了部分代码。复制函数是在我们的核心应用程序中定义的。我只知道我面临的问题。但我无法找到解决我的问题的方法。在这里,类型并不像我向您解释的那样重要。我相信设置差异应该是明确的,并使用std::copy
。与交换
和运算符不同