随笔分类 -  C++

pow()函数结果强制转化为int造成误差的分析
摘要:开发环境:codeblocks,编译器gcc 在计算102时调用pow(10, 2),再强制类型转换为int类型后输出: 得到的结果却是:99 这是因为 double pow(double x, double y) ,返回值是采用数值逼近的方法得到的double类型值。例如返回值为99.999999 阅读全文

posted @ 2019-03-13 11:38 zkfopen 阅读(1225) 评论(0) 推荐(0)

warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
摘要:在C++中, 会跳出警告:warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] 改成下面会通过warning 或者改成下面: 原因解析: 我们在学习c或者c++的时候都知道,如果在赋值操作 阅读全文

posted @ 2019-03-13 11:01 zkfopen 阅读(24306) 评论(1) 推荐(3)

error: no matching function for call to 'std::exception:exception(const char[16])'
摘要:环境:codeblocks 语言:C++ 在执行:throw new exception("queue is empty.");时 遇到问题:error: no matching function for call to 'std::exception:exception(const char[16 阅读全文

posted @ 2019-03-07 17:14 zkfopen 阅读(1816) 评论(0) 推荐(0)

C++中,有哪4种与类型转换相关的关键字?各有什么特点?应该在什么场合下使用?
摘要:转:https://www.cnblogs.com/mjiang2017/p/9358032.html C++中,四个与类型转换相关的关键字:static_cast、const_cast、reinterpret_cast、dynamic_cast。 static_cast 特点:静态转换,在编译处理 阅读全文

posted @ 2019-02-19 11:11 zkfopen 阅读(321) 评论(0) 推荐(0)

delete 和 delete []的区别
摘要:(1). 针对简单类型 使用new分配后的不管是数组还是非数组形式内存空间用两种方式均可 如: int *a = new int[10]; delete a; delete [] a; 此种情况中的释放效果相同,原因在于:分配简单类型内存时,内存大小已经确定,系统可以记忆并且进行管理,在析构时,系统 阅读全文

posted @ 2018-11-13 16:56 zkfopen 阅读(819) 评论(0) 推荐(0)

导航