1
我想要一個指向模板結構數組的const指針。我遇到了一個錯誤,並且我對C++不是很熟悉,所以我不確定從哪裏開始。有人可以解釋如何正確地做到這一點,我做錯了什麼?提前致謝。C++ - 指向模板數組的指針struct
結構:
template <typename T> struct FrequencyEntry {
unsigned short freq;
T result;
};
代碼:
FrequencyEntry<std::string> arr[] = {
{5, std::string("test")},
{10, std::string("asdf")},
};
FrequencyEntry<std::string> * const arr_pointer = &arr;
上最後一行出現的錯誤:
error C2440: 'initializing' : cannot convert from 'FrequencyEntry<T> (*)[2]' to 'FrequencyEntry<T> *const '
'&arr'是數組的地址,應該只指定'arr',讀取錯誤信息 – 2013-04-26 05:13:10