C++模板继承在g++编译中应注意的问题(if you use `-fpermissive', G++ will accept your code, but allowing the use ...)
2010-12-06 23:38
1291 查看
x.cc: In member function `int Derived<T>::g()':
x.cc:6: error: there are no arguments to `f' that depend on a template
parameter, so a declaration of `f' must be available
x.cc:6: error: (if you use `-fpermissive', G++ will accept your code, but
allowing the use of an undeclared name is deprecated)
To make the code valid either use this->f(), or Base<T>::f(). Using the -fpermissive flag will also
let the compiler accept the code, by marking all function calls for which no declaration is visible at the time
of definition of the template for later lookup at instantiation time, as if it were a dependent call. We do not
recommend using -fpermissive to work around invalid code, and it will also only catch cases where functions
in base classes are called, not where variables in base classes are used (as in the example above).
Note that some compilers (including G++ versions prior to 3.4) get these examples wrong and accept above
code without an error. Those compilers do not implement two-stage name lookup correctly. 基本意思是,在模板继承出现的时候,需要在子类中用this来标志从父类中继承过来的成员函数和变量的调用。不然用using声明也行。 在使用模板继承的时候,如子类中有调用父类的成员函数和变量的情况,则需要用用this来调用,或者使用using声明,否则会导致在linux 的G++ 上无法编译通过,错误提示会有如上错误信息。
相关文章推荐
- you must specify a host type if you use `--no-verify'
- django提交表单提示"You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SL
- 关于 Details On launch and content download, your app stores 15.83MB on the user's iCloud被拒问题
- Message 'You cannot use the EurekaLog package in other packages'.
- You requested 'iPhone 6 (9D9EC7F6-20A3-4884-B0EC-551ABE9CE0B0) (8.1 Simulator)', but the available d
- 如果你的软件事关重大,你就会用C++编写它(If your software matters, you will write it in C++)
- 'init(start:end:)' is deprecated: it will be removed in Swift 3. Use the '..<' operator
- After restoring database in SQL Server, if you can't use diagram, execute these sentences
- 编译trimesh2遇到问题:The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant names
- Android 源码编译问题:Your version is: java version "1.6.0_27".The correct version is: Java SE 1.6.
- 解决#1289 - The \'InnoDB\' feature is disabled; you need MySQL built with \'InnoDB\' to have it working的问题
- linux内核编译中的各种问题:No rule to make target `menuconfig'&&Unable to find the Ncurses libraries
- vc6.0 点编译时提示Cannot complile the file 'D:\souce-code\vc-workspace\对话框\MainFrm.h'; no compile tool is
- 解决android studio ADB无响应的问题:If you'd like to retry,then please manually kill "adb.exe"
- Write Code As If You Had to Support It for the Rest of Your Life
- 编译错误error C2587: '_U' : illegal use of local variable as default parameter的问题
- 【buildroot-2011.11】You may have to install 'g++' on your build machine
- MySQL connector C++在Linux下编译undefined reference to 'get_driver_instance'问题
- 解决Navicat数据传输问题:The‘InnoDB’feature is disabled; you need MySQL built with ‘InnoDB'...
- 解决android studio ADB无响应的问题:If you'd like to retry,then please manually kill "adb.exe"