共 35 篇文章
显示摘要每页显示  条
分别为:static_cast , dynamic_cast , const_cast , reinterpret_cast.在进行下行转换时,dynamic_cast具有类型检查的功能,比 static_cast更安全。//结果为null,向下转换失败 if(b==NULL) { cout<<"null"<<endl; } else { cout<<"not null"<<endl; } c=dynamic_cast<C*>(a);//结...
//将字符串以16进制形式输出 QString cmd = 0x0a; qDebug() <<"cmd:"<< cmd.toAscii().toHex();Cpp代码 static const char mydata[] = { 0x00, 0x00, 0x03, 0x84, 0x78, 0x9c, 0x3b, 0x76, 0xec, 0x18, 0xc3, 0x31, 0x0a, 0xf1, 0xcc, 0x99, 0x6d, 0x5b }; QByteArray bd = QByteArray::fromRawData(mydata, size...
// 注意参数是 &str,而不是str strcpy(str, "hello");  cout<< str <<endl; free(str); }      示例4.2用指向指针的指针申请动态内存。char *p = (char *)malloc(sizeof(char) * num);public : Obj(void){ cout <<“Initialization” <<endl; }  ~Obj(void){ cout <<“Destroy” &...
看下面的例子: class String { public: String(const char *str=NULL); String(const String &other); //copy constructor virtual ~String(); String &operator=(const String &other);//assignment operator private: char *m_data; }33. 明智地运用inlining inline函数背后的整个观念是,“对此函数的每一个调用行动”都以函数...
Effective C++笔记:C++组成及类内部常量的实现Effective C++笔记:C++组成及类内部常量的实现。const double b;其次,类中的const成员变量不是在编译时刻确定的(这有点类似C#的readonly),这意味着你可能没法用这个常量作为一个数组大小去初始化一个数组。其一,C++只支持在类内部直接初始化整型的(int/long/char/bool)的static const变量...
//到char的const指针char const *pc1; //到const char的指针const char *pc2; 从右向左读的记忆方式:cp is a const pointer to char.pc2 is a pointer to const char.用法3:const修饰函数传入参数将函数传入参数声明为const,以指明使用这种参数仅仅是为了效率的原因,而不是想让调用函数能够修改对象的值。用法5:const修饰成员函数const对...
关于C++中的const【精】关于C++中的const【精】1.const常量,如const int max = 100;1) 修饰参数的const,如 void fun0(const A* a ); void fun1(const A& a);原因如下:如果返回值为某个对象为const(const A test = A 实例)或某个对象的引用为const(const A& test = A实例),则返回值具有const属性,则返回实例只能访问类A中的公...
结构体数组初始化结构体数组初始化。city cities[2];city cities[2]={{"A",10000,11},{"B",20000,11}};并不是aleda所说的原因,你可以试一下,即便不要结构体不要字符串struct city{ double population; double housing; double ave;};city cities[2];cities[0]={22,10000,11};cities[1]={22,20000,11};这里与结构体匹配...
帮助 | 留言交流 | 联系我们 | 服务条款 | 下载网文摘手 | 下载手机客户端
北京六智信息技术股份有限公司 Copyright© 2005-2024 360doc.com , All Rights Reserved
京ICP证090625号 京ICP备05038915号 京网文[2016]6433-853号 京公网安备11010502030377号
返回
顶部