【发布时间】:2014-12-30 19:24:53
【问题描述】:
问题的标题并没有透露太多关于我的问题,但我试图用一个短语来解释这个问题。这是问题所在,我在使用 Windows 中的 MinGW 和 Linux 中的 GCC 编译的应用程序中具有类似的代码结构。 Visual Studio 没有任何问题。结构如下:
#include <iostream>
namespace idb
{
class Wrapper
{
public:
template<typename S>
void boo(S& s)
{
bind(s);
}
};
}
namespace idb // <- if this namespace changes, code explodes
{
struct Fulalas
{
int x;
};
}
namespace idb
{
void bind(idb::Fulalas f)
{
std::cout << f.x << std::endl;
}
}
namespace app
{
class Foo
{
public:
void func()
{
idb::Fulalas f;
f.x = 5;
w.boo(f);
}
private:
idb::Wrapper w;
};
}
int main()
{
app::Foo f;
f.func();
return 0;
}
问题是为什么在 GCC/MinGW 中将 idb::Fulalas 更改为 aaa::Fulalas(或任何所需的名称)会产生以下错误:
..\namespace\main.cpp: In instantiation of 'void idb::Wrapper::boo(S&) [with S = aaa::Fulalas]':
..\namespace\main.cpp:41:11: required from here
..\namespace\main.cpp:11:10: error: 'bind' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
bind(s);
^
..\namespace\main.cpp:26:7: note: 'void idb::bind(aaa::Fulalas)' declared here, later in the translation unit
void bind(aaa::Fulalas f)
【问题讨论】:
-
这不是您的代码,也不是产生此错误消息的代码。请复制并粘贴一个有代表性的测试用例。
-
如果不想利用ADL,可以将
aaa::Fulalas和idb::bind的声明移到调用idb::bind之前的地方 -
这个问题是关于C++的,所以应该去掉C标签
-
@Columbo “这不是你的代码”是什么意思?当然是我的代码,我写的。