template class build errors in android
16lz
2021-01-26
在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 编译时 , 有时会遇见这个错误信息, 这个错误的可能原因是 代码中的变量 有重复的定义。
更多相关文章
- 【Android】- MediaPlayer错误之MediaPlayer start called in st
- [Android]编译错误:Could not get unknown property 'release' f
- android 细节之An internal error occurred during: "Launching
- 我的Android进阶之旅------>解决错误:You need to use a Theme.Ap
- android studio 中 java.lang.NoClassDefFoundError:retrofit2.R
- Android(安卓)Studio Can not reslove *的解决方案
- Android(安卓)添加Library出现错误Error:(2, 0) Plugin with id
- vue中判断是iOS,安卓,以及微信的方法
- Android(安卓)Listener侦听的N种写法