我看着this excellent answer但無法弄清楚如何將其應用到該剪斷:C++:如何獲取指向2維動態數組的指針?
//this is in the .hpp file
std::atomic<int> size = 10;
std::recursive_mutex *locks[2];
//in some function of the class
//it's important that the 2nd array dimension is dynamic
the_lock[0] = new std::recursive_mutex[size];
the_lock[1] = new std::recursive_mutex[size];
std::recursive_mutex (*locks_2)[2][size] = &locks;
分配給我
error: cannot convert ‘std::recursive_mutex* (*)[2]’ to ‘std::recursive_mutex (*)
[2][(((sizetype)(((ssizetype)((**here be long type information, since I'm using
templates a lot**, long unsigned int, std::less<long unsigned int>
>::size.std::atomic<long unsigned
int>::<anonymous>.std::__atomic_base<_IntTp>::operator
std::__atomic_base<_IntTp>::__int_type<long unsigned int>()) + -1)) + 1)]’ in
initialization
我怎樣才能獲得一個指向「鎖定」?
Arrrr ...請不要叫你的互斥鎖「鎖」。互斥體是一個互斥體,鎖是一個鎖。 –
對不起。我試圖從一本書中實現Java風格的僞代碼,並且保留名字以避免混淆 – mort
好的 - 我認爲這更多的是關於Java而不是關於你:-)(或者至少關於這本書。) –