为什么使用boost::function绑定类成员函数时,类的析构函数不能为虚函数
来源:互联网 发布:神州融大数据风控平台 编辑:程序博客网 时间:2024/05/21 08:45
这是否与模板在编译时动态绑定有关???
#include<iostream>
#include<string>
#include<boost/function.hpp>
#include<vector>
class CBase {
public:
//CBase();
//~CBase();
public:
virtualvoid print(const std::string& vInfo) {std::cout <<"base class member print function:" << vInfo << std::endl;}
};
class CDerive :public CBase {
public:
//CDerive();
//~CDerive(); //why?
public:
virtualvoid print(const std::string& vInfo) {std::cout <<"derive class member print function:" << vInfo << std::endl;}
};
void globalPrint(const std::string& vInfo)
{
std::cout <<"global print function:" << vInfo << std::endl;
}
class FunctionObj {
public:
//FunctionObj();
//~FunctionObj(); why?
public:
voidoperator()(const std::string& vInfo) {std::cout <<"function object print function:" << vInfo << std::endl;}
};
int main (int argc,char * const argv[]) {
// insert code here...
std::vector<boost::function<void(const std::string&)> > FuncVec;
FuncVec.push_back(&globalPrint);
FuncVec.push_back(FunctionObj());
FuncVec[0]("0");
FuncVec[1]("1");
boost::function<void(CBase*,const std::string&)> Func0;
Func0 = &CBase::print;
CBasebase;
Func0(&base,"2");
boost::function<void(CDerive*,const std::string&)> Func1;//why can't be CBase
CDerive derive;
Func1 = &CDerive::print;
Func1((&derive),"3");
return 0;
}
- 为什么使用boost::function绑定类成员函数时,类的析构函数不能为虚函数
- boost::bind boost::function绑定万能函数测试2(类成员函数和虚函数)
- 构造函数为什么不能为虚函数 & 基类的析构函数为什么要为虚函数
- C++之静态成员函数为什么不能为虚函数
- c++静态成员函数为什么不能为虚函数?
- boost::function 通过boost::bind调用类成员函数
- boost::function(函数)实现普通函数和类成员函数的回调
- 为什么static 成员函数不能为const
- 为什么基类的析构函数为虚函数
- boost::bind 绑定成员函数
- 为什么构造函数不能声明为虚函数,析构函数可以声明为虚函数
- 为什么构造函数不能为虚函数,而析构函数可以为虚函数?
- 为什么构造函数不能为虚函数,而析构函数可以为虚函数
- 成员函数模板不能为虚函数
- 为什么构造函数不能为虚函数
- 为什么构造函数不能为虚函数
- 为什么构造函数不能为虚函数
- 构造函数为什么不能为虚函数
- Annotation学习入门的几篇文章
- PCB中plane和layer的区别
- 朝闻道,夕死可矣
- windows phone7开发环境的搭建大致步骤
- wxString与各种数据类型之间的转换(摘自:wiki.wxwidgets.org)
- 为什么使用boost::function绑定类成员函数时,类的析构函数不能为虚函数
- tcl脚本语言
- html控件,html服务器控件,web服务器控件三者区别
- Caused by: java.sql.SQLException: No database selected
- 黑马学习第一天
- v$archived_log——记录归档日志的信息!
- 懒加载分析情况
- IEEE 802.15.4 CSMA/CA机制
- Matlab矩阵操作基础,学习笔记...