简体   繁体   English

我自己的copy()函数与std :: copy()冲突

[英]My own copy() function collides with std::copy()

I have a header file. 我有一个头文件。 In this header I want to use a map for a class. 在这个标题中,我想使用一个类的地图。 But after I include I get a no matching function error , because I have a copy() function in the project(really big project). 但是在我包含之后我得到了一个no matching function error ,因为我在项目中有一个copy()函数(真正的大项目)。 I saw on this website http://www.sgi.com/tech/stl/download.html that map contains a using std::copy so I guess it collides with that. 我在这个网站http://www.sgi.com/tech/stl/download.html上看到,该地图包含一个使用std :: copy,所以我猜它与之相撞。

I cannot make any changes to the copy function, so is there a way I can use map in this header file ? 我无法对复制功能进行任何更改,所以有没有办法在这个头文件中使用map? (no other place). (没有其他地方)。 Is there a way so my copy functions don't collide ? 有没有办法让我的复制功能不会发生冲突?

I use Visual Studio 2008 on Windows 7. 我在Windows 7上使用Visual Studio 2008。

The error message suggests that your function is not visible to the translation unit, so make sure you include the header. 错误消息表明您的功能对翻译单元不可见,因此请确保包含标题。

Also, I doubt <map> has anything like using std::copy . 另外,我怀疑<map>有什么像using std::copy You sure about this one? 你确定这个吗?

In algobase.h (which is not standard C++), the using directives are parsed only if __STL_USE_NAMESPACES is defined. algobase.h (不是标准C ++)中,仅在定义了__STL_USE_NAMESPACES解析using指令。 You should undefine it before including the header: 在包含标题之前,您应该取消定义它:

#undef __STL_USE_NAMESPACES
#include "algobase.h"
#endif

You should be able to wrape the map include in a namespace ie 你应该能够将地图包括在名称空间中


    namespace StopCollision
    { #include <map> }

Then the map copy function would be available via StopCollision::std::copy . 然后可以通过StopCollision::std::copy获得地图复制功能。 This is very crude, but would solve your problem. 这非常粗糙,但可以解决您的问题。

To the best of my knowledge the map stl class doesn't have a copy function. 据我所知,map stl类没有复制功能。 It is probably an include issue, you could try using a forward reference to the class that contains the map and copy function. 这可能是一个包含问题,您可以尝试使用包含地图和复制功能的类的前向引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM