编译器错误 - 未在此范围内声明

时间:2018-03-01 02:10:26

标签: c++ templates inheritance

以下代码无法编译,我没有看到错误。

template<class block>
struct bit_const_traversal {
  block d_b;
};

template<class block>
class bit_traversal : public bit_const_traversal<block> {
public:
  block it() const { return d_b;}  
};

#include <iostream>

int main() {
  bit_traversal<unsigned long> a;
  std::cerr << a.it() << '\n';
  return 0;
}

编译器说

j.cpp: In member function 'block bit_traversal<block>::it() const':
j.cpp:10:29: error: 'd_b' was not declared in this scope
   block it() const { return d_b;}
                         ^~~

我在mac上使用gcc 7.3.0到homebrew。 uname -a产生

Darwin Marks-iMac.local 17.4.0 Darwin Kernel Version 17.4.0:Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1 / RELEASE_X86_64 x86_64

0 个答案:

没有答案