struct plcmtnew { double d1; double d2; }; char buffer[1]; try { int *pc = new(buffer) int(4); cout << *pc << endl; plcmtnew *pn; pn = new(buffer)plcmtnew{2.2,3.4}; cout << pn->d1 << endl; cout << pn->d2 << endl; } catch (bad_alloc &ba) { cout << ba.what() << endl; exit(EXIT_FAILURE); }
引用 4 楼 pengzhixi 的回复:[quote=引用 3 楼 yshuise 的回复:] 不能用数组,而是用malloc,new申请的内存。是否是动态分配的都没关系。
[quote=引用 3 楼 yshuise 的回复:] 不能用数组,而是用malloc,new申请的内存。
引用 3 楼 yshuise 的回复:不能用数组,而是用malloc,new申请的内存。是否是动态分配的都没关系。
不能用数组,而是用malloc,new申请的内存。
64,683
社区成员
250,491
社区内容
加载中
试试用AI创作助手写篇文章吧