【发布时间】:2011-09-02 19:39:16
【问题描述】:
我想在 MSVC2010 中用零指针初始化 c 字符串数组
// Foo.h
#pragma once
class Foo {
int sz_;
char **arr_;
public:
Foo();
~Foo();
// ... some other functions
};
// Foo.cpp
#include "Foo.h"
#define INITIAL_SZ 20
Foo::Foo() : sz_(INITIAL_SZ) {
// there I have to initialize arr_ (dynamic array and can be enlarged later)
arr_ = (char **)calloc(INITIAL_SZ * sizeof (char *)); // ???
// or maybe arr_ = new ...
}
如何正确初始化arr_?我不被允许使用 STL、MFC 等。
【问题讨论】:
-
只是好奇。为什么没有 STL?到目前为止,您还尝试过什么?实际上,您所拥有的
calloc()会将所有内容初始化为零(NULL)。 -
如果不是
class位,我会标记这个 C... -
@yasouser - 这是客户的要求
标签: c++ arrays c++11 crt c-strings