[問題] 動態宣告class的array並使用constructor
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
none
問題(Question):
我想要動態宣告object的array 該array 共n個object
然後每一個object的constructor再動態宣告一個int array
該array 共m個int
class myclass
{
public:
int* array;
myclass(int n);
};
myclass::myclass(int n)
{
array = new int[n];
}
int main()
{
int n = 7;
int m = 13;
myclass *x;
//打 x = new myclass[n](m); 不對
//打 x = new myclass(m)[n]; 也不對
}
請問要怎麼做?
不想用vector...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.246.179
推
05/28 11:34, , 1F
05/28 11:34, 1F
推
05/28 12:07, , 2F
05/28 12:07, 2F
→
05/28 12:19, , 3F
05/28 12:19, 3F
→
05/28 12:19, , 4F
05/28 12:19, 4F
→
05/28 15:16, , 5F
05/28 15:16, 5F
用多少 取多少~
當我所要用到的只是 單純的array 沒用到其他東西
我會希望是用array 而不是vector
因為我所要實作的程式 大多是要跑大測資 要比速度的
之前我有一份程式 就是覺得跑很慢 我把所有vector改成 int*
速度就真的快了有10幾秒以上
※ 編輯: musicJD 來自: 111.255.249.95 (05/29 01:06)
→
05/29 01:34, , 6F
05/29 01:34, 6F
→
05/29 01:51, , 7F
05/29 01:51, 7F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 3 篇):