如何初始化c-strings数组(无stl)

Loo*_*oom 0 c++ arrays c-strings crt c++11

我想在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 ...
}
Run Code Online (Sandbox Code Playgroud)

如何正确初始化arr_?我不被允许使用STL,MFC等.

Ale*_*ler 5

arr = new char*[INITIAL_SZ](); 会做 - 你甚至可以把它放在初始化列表中.