checked_delete问题: Beyond the C++ STL: an introduction to boostdeleter::do_it
来源:互联网 发布:java程序员等级划分 编辑:程序博客网 时间:2024/06/05 13:34
环境:
Visual studio 2017
boost库编译选项: msvc141,multi,win64,debug,shared
demo工程设置: debug, win32
问题源:
《Beyond the C++ STL: an introduction to boost》书上Part I, Library 3, checked_delete章节
如果把 deleter.h, deleter.cpp, to_be_deleted.h三个文件内容整合到一个文件里,
编译后会提示 " warning C4150: 删除指向不完整“to_be_deleted”类型的指针;没有调用析构函数"
运行后调用 deleter::do_it 时会间接调用到 ~to_be_deleted()。
调用 deleter::delete_it 时则不会间接调用到 ~to_be_deleted()。
最后调用完 ~to_be_deleted()程序结束时才报一个异常错误。
很奇怪的地方啊!看来是编译器工作方式的不同导致的吧。。。
// deleter.hclass to_be_deleted;class deleter {public:void delete_it(to_be_deleted* p);void do_it(to_be_deleted* p);};// deleter.cpp//#include "deleter.h"#include "boost/checked_delete.hpp"void deleter::delete_it(to_be_deleted* p) {delete p;}void deleter::do_it(to_be_deleted* p) { boost::checked_delete(p); // typedef char type_must_be_complete[sizeof(T)]; 所有代码放入一个文件,这句居然能编译通过??}// to_be_deleted.h#include <iostream>class to_be_deleted{public:~to_be_deleted() {std::cout <<"I'd like to say important things here, please.";}};// Test application//#include "deleter.h"//#include "to_be_deleted.h"int main() {to_be_deleted* p = new to_be_deleted;deleter d;d.delete_it(p);d.do_it(p);}
阅读全文
0 0
- checked_delete问题: Beyond the C++ STL: an introduction to boostdeleter::do_it
- Beyond the C++ Standard Library: An Introduction to Boost
- Beyond Workflow : An Introduction to Vitria BusinessWare
- Beyond the C++ Standard Library: An Introduction to Boost by Bjцrn Karlsson
- An Introduction To The SQLite C/C++ Interface
- An Introduction To The SQLite C/C++ Interface
- An Introduction to the JAIN SIP API
- An Introduction to the Extended Kalman Filter
- An Introduction to the Theory of Computation
- an-introduction-to-the-raphael-js-librar
- An Introduction to the Raphael JS Library
- An introduction to Objective-C Meta Class
- An Introduction to Thread in the upcoming book From: Introduction to the C++ Boost Libraries
- An Introduction to Struts
- An introduction to LaTeX2e
- An Introduction To Ajax
- An introduction to SOA
- An introduction to Microcode
- JDBC和数据库连接池学习笔记
- 1002. A+B for Polynomials
- 12.13
- motion+itchat
- Oracle 11g AMM与ASMM切换
- checked_delete问题: Beyond the C++ STL: an introduction to boostdeleter::do_it
- java.lang.OutOfMemoryError: PermGen space异常解决方案
- SpringMVC四大注解 Component·Controller·Service·Repository
- Json
- AndroidStudio更新3.0.1问题总结(一)
- 关于docker 的一些简单的操作命令
- LeetCode.200 Number of Islands
- Capstone训练营6
- iOS 11 关于相册权限的问题