
C/C++
ld_hust
除了思考,很懒
展开
-
C++中头文件相互包含的几点问题
设我们有两个类A和B,分别定义在各自的有文件A.h和B.h中,但是在A中要用到B,B中也要用到A,但是这样的写法当然是错误的:class B;class A{ public: B b;};class B{ public: A a;};因为在A对象中要开辟一块属于B的空间,而B中又有A的空间,是一个逻辑错误,无法实现的。在这里我们只需要把其中的一个A类中的B类型成员改成指针形式就可以避免这个无限延伸的怪圈了。为什么要更改A而不是B?因为就算你在B2010-04-02 16:29:46 · 164 阅读 · 0 评论 -
全局变量和局部变量在内存里的区别
原创 2010-11-09 21:55:12 · 99 阅读 · 0 评论 -
字节序
这些字节序是指整数在内存中保存的顺序 这个叫做主机序 最常见的有两种 1 . Little endian :将低序字节存储在起始地址 2 . Big endian :将高序字节存储在起始地址 LE little-endian 最符合人的思维的字节序 地址低位存储值的低位 地址高位存储值的高位 怎么讲是最符合人的思维的字节序,是因为从人的第一观感来说 低位值小,就应该放在内存地址小的地方,也即内存地址低位 反之,高位值就应该放在内存地址大的地方,也即内存地址高位 BE big-endian 最直观的字节序原创 2010-12-01 21:03:03 · 172 阅读 · 0 评论 -
Overview of Protocol Buffers Developer Guide
ls, data storage, and more.This documentation is aimed at Java, C++, or Python developers who want to use protocol buffers in their applications. This overview introduces protocol buffers and tells you what you need to do to get started – you can then go原创 2010-12-07 10:31:53 · 149 阅读 · 0 评论 -
Language Guide of Protocol Buffers Developer Guide
ing ServicesOptionsGenerating Your ClassesThis guide describes how to use the protocol buffer language to structure your protocol buffer data, including .proto file syntax and how to generate data access classes from your .proto files.This is a re原创 2010-12-07 10:34:22 · 107 阅读 · 0 评论 -
Style Guide of Protocol Buffers Developer Guide
and easy to read.Message And Field NamesUse CamelCase (with an initial capital) for message names – for example, SongServerRequest. Use underscore_separated_names for field names – for example,song_name.message SongServerRequest { required string原创 2010-12-07 10:36:24 · 101 阅读 · 0 评论 -
Encoding of Protocol Buffers Developer Guide
r protocol buffer messages. You don't need to understand this to use protocol buffers in your applications, but it can be very useful to know how different protocol buffer formats affect the size of your encoded messages.A Simple MessageLet's say you h原创 2010-12-07 10:37:19 · 94 阅读 · 0 评论 -
Protocol Buffer Basics: C++
toDefine message formats in a .proto file.Use the protocol buffer compiler.Use the C++ protocol buffer API to write and read messages.This isn't a comprehensive guide to using protocol buffers in C++. For more detailed reference information, see原创 2010-12-07 10:38:21 · 113 阅读 · 0 评论 -
Techniques of Protocol Buffers Developer Guide
lso send design and usage questions to the Protocol Buffers discussion group.Streaming Multiple MessagesIf you want to write multiple messages to a single file or stream, it is up to you to keep track of where one message ends and the next begins. The原创 2010-12-07 10:39:13 · 82 阅读 · 0 评论 -
JobFlow要继续考虑的问题
2010-09-17 22:35:11 · 131 阅读 · 0 评论 -
C++单例不可继承
rivate,最坏也是protected2. 构造函数只被调用一次,以初始化static对象。 所以如果B1,B2,继承至单例A,则不可以实现在程序运行的整个过程中既有一个B1单例又有一个B2单例,而且两个单例不存在依赖关系,原因是B1、B2共享一个A基类,而B1和B2的静态对象声明在A中,即两者共享一个base静态对象,因此对B1和B2两次调用初始化函数(GetInstance)时候,实际上基类A的静态对象会有两次初始化的动作(GetInstance),当然,基类的静态对象只会实例化一次,具2010-09-17 17:24:01 · 335 阅读 · 0 评论 -
C++库介绍
2010-04-02 16:30:18 · 167 阅读 · 0 评论 -
头文件互包含于名字空间的相关问题
题.在头文件里面定义,虽然可以使定义部分和实现部分分开,但是,当文件比较多的时候,一个头文件往往被重复包含了很多次,间接的造成了,很多内容被重复定义了好几次,从而产生编译器错误.简单的解决方法是头文件使用下面的格式:#ifndef __filename_h__#define __filename_h__//文件的内容#endif 这样的结构可以保证每个文件中的内容只被声明一次.似乎问题解决了,但是,这只解决了一个问题而已.还有一个问题,比较复杂,解决起来也是比较难的,就是文件的相互包2010-07-17 20:27:36 · 373 阅读 · 0 评论 -
用Valgrind查找内存泄漏和无效内存访问
原创 2010-07-20 09:29:15 · 122 阅读 · 0 评论 -
snprintf与strncpy效率对比
原创 2010-07-20 09:31:48 · 369 阅读 · 0 评论 -
关于auto_ptr的忠告
2010-08-26 16:21:45 · 81 阅读 · 0 评论 -
优秀的框架工具
列化工具,可以支持C++/Java/C#等 Action Script: http://code.google.com/p/protobuf-actionscript3/ Action Script: http://code.google.com/p/protobuf-actionscript/ Action Script: http://code.google.com/p/protocol-buffers-actionscript/ C: http://code原创 2010-09-08 10:13:48 · 111 阅读 · 0 评论 -
log4cxx编译方法
原创 2010-09-08 10:30:40 · 72 阅读 · 0 评论 -
C++静态成员与静态成员函数小结
包括静态数据成员和静态函数成员两部分。 一 静态数据成员: 类体中的数据成员的声明前加上static关键字,该数据成员就成为了该类的静态数据成员。和其他数据成员一样,静态数据成员也遵守public/protected/private访问规则。同时,静态数据成员还具有以下特点: 1.静态数据成员的定义。 静态数据成员实际上是类域中的全局变量。所以,静态数据成员的定义(初始化)不应该被放在头文件中。 其定义方式与全局变量相同。举例如下: xxx.h文件 class base{ private: static c原创 2010-09-16 15:48:25 · 107 阅读 · 0 评论 -
小对象的分配技术
原创 2011-03-21 12:01:14 · 187 阅读 · 0 评论