template class build errors in android

在Android 中 ,如果一个模板类 A 继承与 模板类 B ,当A 引用B 的共有成员时, 如果不加 “this->” , 会产生“was not declared in this scope”错误

例如:

template <typename T> struct B {
	  int m;
	  int n;
	  int f ();
	  int g ();
	};
	int n;
	int g ();
	template <typename T> struct C : B<T> {
	  void h ()
	  {
	    m = 0; // error
	    f ();  // error
	    n = 0; // ::n is modified
	    g ();  // ::g is called
	  }
	};

 真确的写法是 :

 

	template <typename T> void C<T>::h ()
	{
	  this->m = 0;
	  this->f ();
	  this->n = 0
	  this->g ();
	}
 


官方解释是 :http://gcc.gnu.org/gcc-3.4/changes.html
In a template definition, unqualified names will no longer find members of a dependent base (as specified by [temp.dep]/3 in the C++ standard)






2. another error : "expected unqualified-id before numeric constant"

用GCC 编译时 , 有时会遇见这个错误信息, 这个错误的可能原因是 代码中的变量 有重复的定义。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值