c++奇怪的搞法汇总
来源:互联网 发布:python 程序 编辑:程序博客网 时间:2024/05/01 14:58
1 静态局部变量
int WorkEvent::GenerateId()
{static int uiEventId = 0;
return uiEventId++;
}
2 define and enum 预编译是顺序的,不能随便调整
#define MAKE_UNION(VAR) VAR
#define MAKE_STRINGS(VAR) #VAR
#define APP_EVENT_TYPE(DO) DO(DIGIT), DO(DIGIT2)
typedef enum
{
APP_EVENT_TYPE(MAKE_UNION)
}APP_EVENT_NAME;
const string g_strAryAppEventName[EVENT_NAME_END+1] =
{
APP_EVENT_TYPE(MAKE_STRINGS)
};
3 delete
#define SAFE_DELETE(p) {if(NULL != p) {delete p; p = NULL;}}
#define SAFE_DELETE_ARRAY(p) {if(NULL != p) {delete [] p; p = NULL;}}
4
Before C++11, we could only perform in-class initialization on static const members of integral or enumeration type.Stroustrup discusses this in his C++ FAQ, giving the following example:
class Y { const int c3 = 7; // error: not static static int c4 = 7; // error: not const static const float c5 = 7; // error: not integral};
5 类型转化
#include <string>
#include <iostream>
#include <sstream>
int main(void) {
std::string str;
std::stringstream stream;
stream<<"1"<<2;
stream>>str;
std::cout<<str<<std::endl;
return 0;
}
6 string *ptString1 = false;
//string *ptString1=true; compile error
string *ptString1 = false;
if (!ptString1) {
cout << "true1" << endl;
}
string *ptString2 = NULL;
if (!ptString2) {
cout << "true2" << endl;
}
string *ptString3 = new string;
if (ptString3) {
cout << "true3" << endl;
}
int x = 0;
if (!x) {
cout << "true4" << endl;
}
int y = 1;
if (y) {
cout << "true5" << endl;
}
java all compile error
- c++奇怪的搞法汇总
- Android Intent的基本搞法
- 常见组件对象的搞法
- 【清明】奇怪的初赛汇总
- 奇怪的c语言
- hdu 5015 233 Matrix(最快的搞法)
- 奇怪的c语言声明
- c#很奇怪的代码
- 奇怪的C++operator重载
- 奇怪的C语言代码
- 奇怪的C语言写法
- 奇怪的C语言表达式
- Problem C: 奇怪的分式
- ios奇怪问题汇总
- 小规模、低性能、低流量的网站该如何搞法
- 最长上升子序列的O(nlogn)搞法
- C语言的一个奇怪的问题?
- 奇怪的c局部静态变量
- DBCP连接池详解
- 对JSP页面传值中文乱码的简单解决方法
- 门内门外看招聘
- 使用HttpClient发送http请求,并解析从服务器端返回的数据
- Android提高第二十一篇之MediaPlayer播放网络视频
- c++奇怪的搞法汇总
- 如何申请Appkey
- c# 串口的读写
- 使用Vitamio打造自己的Android万能播放器(4)——本地播放(快捷搜索、数据存储)
- PHP导出excel
- 什么是ORM及ORM的详解
- 使用Vitamio打造自己的Android万能播放器(5)——在线播放(播放优酷视频)
- 使用Vitamio打造自己的Android万能播放器(7)——在线播放(下载视频)
- zoj 1409 Communication System