boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - sizeof(string)
相关主题
C++一个string的小问题
make 时候遇到 undefined reference 怎么办?
typedef basic_string string;
一个c++小问题
compile error
C++ Interview Question
在子函数内开内存,返回主函数指针然后释放空间是不是很糟糕的(转载)
问个简单的memory allocation 的问题。
谁记得一个讨论c++的网站
a=(char **)malloc(12*sizeof(char *)) 是什么意思?
相关话题的讨论汇总
话题: string话题: tp话题: chart话题: sizeof话题: basic
进入Programming版参与讨论
1 (共1页)
b******w
发帖数: 52
1
I am a little confused about the sizeof(string) = 4.
Since string is a specialized basic_string, and basic_string is derived
from _String_base.
_String_base has three protected pointers:
_Tp* _M_start;
_Tp* _M_finish;
_Tp* _M_end_of_storage;
thus sizeof(string) should be 12 instead of 4?
is there anybody to elaborate on this?
template class _Traits = char_traits<_CharT>,
class _Alloc = __STL_DEFAULT_ALLOCATOR(_CharT) >
class basic_string;
typedef basic_
X****r
发帖数: 3557
2
You were not looking at the actual code that you were compiling.
Try to find the actual string header file in your system, and you'll see.

【在 b******w 的大作中提到】
: I am a little confused about the sizeof(string) = 4.
: Since string is a specialized basic_string, and basic_string is derived
: from _String_base.
: _String_base has three protected pointers:
: _Tp* _M_start;
: _Tp* _M_finish;
: _Tp* _M_end_of_storage;
: thus sizeof(string) should be 12 instead of 4?
: is there anybody to elaborate on this?
: template
b******w
发帖数: 52
3
My fault.
thanks.

【在 X****r 的大作中提到】
: You were not looking at the actual code that you were compiling.
: Try to find the actual string header file in your system, and you'll see.

1 (共1页)
进入Programming版参与讨论
相关主题
a=(char **)malloc(12*sizeof(char *)) 是什么意思?
再问一个free()的问题
VC++里一个函数有参数[out]LPWSTR p要不要初始化?
为什么有点函数声明的参数类型但是没有变量名呢?
这个怎么allocate memory?
map析构
effective C++里的memory pool 一问:
why do we still use dynamic allocation?
a string define question (c++)
一个C++ operator new的重载问题
相关话题的讨论汇总
话题: string话题: tp话题: chart话题: sizeof话题: basic