09 2014 档案
摘要:一、sizeof是关键字,不是函数sizeof是C/C++中的一个关键字,其作用就是返回一个对象或者类型所占的内存字节数。二、delete时的中括号比如: int *p = new int[23]; delete []p; 开辟数组时才使用中括号比如:一个结构体StructStudent *p =...
阅读全文
摘要:关于二者执行的顺序,正常来说,是:构造父类-构造子类-析构子类-析构父类 (栈的顺序)比如 class F{}; class S : public F{}; S* s = new S(); delete s; 就会按照上面的顺序执行。但是,class F{}; class S : public F...
阅读全文
摘要:简单工厂模式:用一个类负责创建实例的任务,通常是此类中的一个static函数具体负责,此函数中包含了必要的逻辑判断,根据客户端的选择条件动态实例化相关的类。这些实例化的类都派生自同一个父类。使用简单工厂模式,在新增分支时,要新增一个功能子类同时在工厂类中增加逻辑判断分支。//简单工厂模式//父类cl...
阅读全文
摘要:一般用法 switch ( expression ) statement常用用法switch ( expression ) { case const-expression : statement [ default : statement ] }在C++中,expression必须是int型 cha...
阅读全文
摘要:1、纯虚函数class Base{public: Base(){}; virtual ~Base(){};};//类A是一个抽象类class A : public Base{public: A(){} virtual ~A(){} virtual void fun() ...
阅读全文
摘要://获取文件名后缀char* fileName = "pwave.sgy";std::string file_str = fileName;int pos = file_str.rfind('.') + 1;std::string temp = file_str.substr( pos );
阅读全文
摘要:1、substr( size_type off, size_type count ) 从源串中复制子串#include //复制子串std::string str1("新和xinbingcup");std::string str_sub = str1.substr( 0, 4 );//substr(...
阅读全文
摘要:1、QString、std::string转化成char*#include #include int main(){ QString str_Q("cupcupy北京"); int j = str_Q.length(); //11,一个汉字算两个字符 std::string str...
阅读全文
摘要:/*!\brief 判断两个浮点数是否相等\return 相等返回true 不等返回false\param float absfloat - 允许的最小误差范围*/#include "limits.h"using namespace std;bool equal_float( float fa, f...
阅读全文

浙公网安备 33010602011771号