【发布时间】:2011-06-28 01:29:27
【问题描述】:
我想创建一个函数来为数组分配内存。假设我有这个:
PWSTR theStrings[] = { L"one", L"two", L"three" };
void foo(PWSTR a, int b) {
a=new PWSTR[b];
for(int i=0;i<b;i++) a[i]=L"hello";
return;
}
int main() {
foo(theStrings,4);
}
我的问题是,你如何使函数 foo 和该函数的调用,以便在调用 foo 之后,theStrings 将包含四个“hello”
谢谢 :) 雷纳杜斯
【问题讨论】:
-
改用
std::vector<std::string>。 -
我必须使用 PWSTR,因为这些值将被传递到需要 PWSTR 数组的 Windows API
-
您能在适当的时候使用
std::wstring并用c_str()解压原始数组吗?
标签: c++ visual-c++ parameter-passing pass-by-reference