2016-11-24 16 views
1

我想编译一个C++软件,它给我几个编译 错误。此错误是关于无法解析的成员函数。继承的成员函数似乎没有声明,是怎么回事?

这个问题应该包含所有需要回答的问题。但是,如果真的如此,我现在应该已经找到了答案。所以请随时拨打 来浏览source code。 此问题中的所有代码不是我的,而是根据GPLv2许可的。

我编译的系统是一台运行红帽企业服务器的IBM PowerPC 740 6.8。使用模块,我已经启用了Clang 3.7。对于IBM PowerPC A2芯片,所有东西都得到交叉编译 ,它是IBM BlueGene/Q超级计算机。这些东西 应该由我的compilation script 照顾,设置需要许多configureCXXFLAGS

的编译错误,我目前与我目前的状态得到(提交 fee0a02)是这一个:

bfmcommqmp.C:183:5: error: use of undeclared identifier 'gather' 
    gather(result_cb, psi, dag); 
    ^

出错行是在bfmcommqmp.C这种方法定义:

168 template <class Float>               
169 void bfmcommQMP<Float>::comm_start(int result_cb, Fermion_t psi, int dag) {  
170  // gather the faces. Routines here are threaded.        
171  // All threads cooperate in gathering.          
172                     
173  // if (this->isBoss() && (me == 0)) {          
174  // this->Error("comm_start checking heap\n"); fflush(stdout);    
175  // mcheck_check_all();             
176  // this->Error("comm_start mcheck_all");fflush(stdout);     
177  // }                  
178                     
179  int me = this->thread_barrier();            
180                     
181  this->thread_barrier();              
182                     
183  gather(result_cb, psi, dag);             
184                     
185  this->thread_barrier();              
186  if (me == 0) {                
187   comm_qmp_start(psi);              
188  }                   
189  this->thread_barrier();              
190                     
191  return;                  
192 } 

这当然是bfmcommQMP课程的一部分。综观相关 头文件,bfmcommqmp.h,人们发现这一类声明:

8 template <class Float>               
    9 class bfmcommQMP : public bfmbase<Float> {          
10 public:                  
11  // QMP thingy-me-bob's              
12  QMP_msghandle_t multi_handle[2];            
13                     
14  QMP_msgmem_t send_ops_msgmem_t[8];           
15  QMP_msgmem_t recv_ops_msgmem_t[8];           
16                     
17  QMP_msghandle_t send_multi_handle;           
18  QMP_msghandle_t send_handles[8];            
19                     
20  QMP_msghandle_t recv_handles[8];            
21  QMP_msghandle_t all_handles;             
22                     
23  Float *simd_rbuf[8];               
24  Float *receive_area;               
25                     
26  int num_op;                 
27                     
28  virtual bool isBoss();              
29                     
30  virtual void recv_init(void);            
31  virtual void recv_end(void);             
32                     
33  virtual void comm_init(void);            
34  virtual void comm_end(void);             
35  virtual void comm(int result_cb, Fermion_t psi, int dag);     
36  virtual void comm_start(int result_cb, Fermion_t psi, int dag);    
37  virtual void comm_qmp_start(Fermion_t psi);         
38  virtual void comm_qmp_complete(void);          
39  virtual void comm_merge(void);            
40  virtual void comm_complete(int result_cb, Fermion_t psi);     
41  virtual void comm_gsum(double &val);           
42  virtual void comm_gsum(double *val, int N);         
43 }; 

bfmbase继承。跳转到包含在 bfmcommqmp.h文件bfm.h,我们发现类的定义,它包含两个gather 方法:

133 template <class Float>               
134 class bfmbase : public bfmarg, public ThreadModel {        
135 public: 

282  void gather(int result_cb, Fermion_t psi, int dag); 
283  void gather(int mu, int result_cb, Fermion_t psi, int dag); 

1018 }; 

从我的理解,bfmcommQMP应该继承了 非虚拟函数gather从类bfmbase。显然情况并非如此, 否则铿会不会抱怨。

我在这里错过了什么?为什么功能gatherbfmcommQMP::comm_start成员函数中不可用?

回答

2

问题是您的派生类是dependent name。您需要使用this->gather()代替基类中的gather(),否则编译器不会从基类中解析gather()。为了简化,

template<class T> struct Base 
{ 
    void f(); 
}; 

template<class T> struct Derived: Base<T> // dependent name 
{ 
    void foo() 
    { 
     this->f(); // won't compile without this-> 
    } 
}; 

另一种方法是做

using Base::f; 
派生 Derived::foo()

或有资格的调用,比如

Base::f(); 

相关:Why do I have to access template base class members through the this pointer?

+0

这也解释了所有其他原因该方法中的调用以'this->'作为前缀!现在我得到一些其他的编译错误,这个似乎解决了。非常感谢你,我在其他地方寻找,并不会想到这样的事情可能是原因。 –

+0

不客气。 [C++模板:完整指南](https://www.amazon.com/Templates-Complete-Guide-David-Vandevoorde/dp/0201734842)是imo,模板上最好的书,告诉你所有你想过的模板。老(2002年)但仍非常相关。作者正在研究对现代C++(C++ 11及更高版本)的更新。 – vsoftco