我有這樣的代碼:聲明未知大小的數組
//Class1.h - this is in a DLL solution
class Sample
{
//members...
}
static Sample m_sample[1]; //size is not known - it will be given by the application that references the DLL
//function to insert data on to array m_sample
void AddSample(Sample** sample, members....)
{
static int index;
sample[index++] = new Sample(members...);
}
//in the cpp file in the EXE solution
void InitSample()
{
AddSample(&m_sample, members....);
}
,這讓我這個錯誤:
error C2664: 'AddSample' : cannot convert parameter 1 from 'Sample (*)[1]' to 'Sample **'
我明白陣列的聲明和函數聲明爲參數是不同的。 我不知道的是如果在DLL編譯時未知大小,如何聲明數組(如同靜態數組和參數) ??
注: 我已經嘗試使用std ::向量作爲容器,這讓我LNK錯誤(未定義的符號),並在谷歌看到,它是使用STL功能不好的設計(或至少這就是我記得)所以請不要建議使用矢量。
我還在學習C++(MFC),指針的概念對我來說還不清楚。
謝謝!
編輯:強調已經嘗試過的載體
數組是**不是**指針,而指針是**不是**數組。使用'std :: vector'。 – StoryTeller
使用'static std :: vector m_sample;' –
_「,並在Google上看到,使用STL函數是錯誤的設計」_tar和羽毛傳播這樣純粹的東西的人! –