偶然发现在C中sizeof(void)是合法的,于是,对它的作用产生了疑问.查阅资料在GNU文档中发现如下解释: In GNU C, addition and subtraction operations are supported on pointers to void and on pointers to functions. This is done by treating the size of a void or of a function as 1. A consequence of
ref:http://bbs.csdn.net/topics/360249561 一个继承了两个虚基类又增加了自己的一个虚函数pif的类,sizeof(指向pif的指针)竟然是8(X86).我是从这里http://www.codeproject.com/KB/cpp/FastDelegate.aspx看到的. 试验代码(VS2010,Win32) #include <iostream>#include <cstdlib> class CBase{public: int
原文:http://blog.sina.com.cn/s/blog_7c983ca60100yfdv.html#SinaEditor_Temp_FontName (1) sizeof是操作符,不是函数. MSDN:The sizeof keyword gives the amount of storage, in bytes, associate with a variable or a type(including aggregate types). This keyword ret
1.sizeof operator sizeof是C语言的一种单目操作符,如C语言的其他操作符++.- - 等,它并不是函数. Queries size of the object or type. 1) returns size in bytes of the object representation of type. 2) returns size in bytes of the object representation of the type, that would be return
sizeof()使用小结 特性0:sizeof是运算符,不是函数 sizeof最基本特性,后面的很多特性都是受到这个特性的影响,正因为sizeof不是函数,因此不把它所要求得长度的对象叫做参数,习惯上叫做操作数. 特性1:sizeof不能求得void类型的长度 不能用sizeof(void),这将导致编译错误:illegalsizeof operand.因为无法声明void类型的变量,可以试试void a; 编译器会报错:illegal use of type 'void'.声明变量的一个重要作
例一: #include <iostream> using namespace std; class A { public: char c; }; class B { public: int a; short b; }; class C { public: int a; short b; char c; }; class D { public: int a; short b; char c; char d; }; class E { public: int a; short b; char c