相关疑难解决方法(0)

在C++模板实例化中查找依赖名称

当我尝试编译此代码时

// void foobar(int); 

template <class T>
struct Foo {
  void bar(T t) { foobar(t); };
};

void foobar(int);

template class Foo<int>;
Run Code Online (Sandbox Code Playgroud)

使用g ++ 4.8.2我收到以下错误消息

foo.cc: In instantiation of ‘void Foo<T>::bar(T) [with T = int]’:
foo.cc:10:16:   required from here
foo.cc:5:27: error: ‘foobar’ was not declared in this scope, and no 
             declarations were found by argument-dependent lookup at 
               the point of instantiation [-fpermissive]
   void bar(T t) { foobar(t); };
                           ^
foo.cc:8:6: note: ‘void foobar(int)’ declared here, later in the translation unit …
Run Code Online (Sandbox Code Playgroud)

c++ templates language-lawyer argument-dependent-lookup

19
推荐指数
2
解决办法
1192
查看次数