我想在MSVC2010如何初始化C字符串數組(不STL)
// 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 ...
}
零個指針初始化C-字符串數組如何正確初始化arr_
?我沒有被允許使用STL,MFC等。
只是好奇。爲什麼沒有STL?還有你到目前爲止嘗試過什麼?其實你在那裏'calloc()'會將所有東西初始化爲零(NULL)。 – yasouser 2011-05-26 17:38:46
如果不是'class'位,我會標記這個C ... – 2011-05-26 17:39:11
@Matthiew - 我也是:) – Loom 2011-05-26 17:54:31