私は C++ の経験がなく、いくつかの C++ コード (具体的にはpaq8lのコード) を変更しようとしています。それらのデータ型の 1 つをパラメータとして渡そうとしていますstd::async
。
int testTest(SmallStationaryContextMap &sscm)
{
return 1;
}
int someOtherMethod()
{
SmallStationaryContextMap sscm(0x20000);
testTest(sscm); // fine
auto future = std::async(testTest, sscm); // compiler error
}
簡単なものが欠けているだけだといいのですが、これによりタイトルにエラーが表示されます。error C2248: 'Array<T>::Array' : cannot access private member declared in class 'Array<T>'
SmallStationaryContextMap:
class SmallStationaryContextMap {
Array<U16> t;
int cxt;
U16 *cp;
public:
SmallStationaryContextMap(int m): t(m/2), cxt(0) {
assert((m/2&m/2-1)==0); // power of 2?
for (int i=0; i<t.size(); ++i)
t[i]=32768;
cp=&t[0];
}
void set(U32 cx) {
cxt=cx*256&t.size()-256;
}
void mix(Mixer& m, int rate=7) {
*cp += (y<<16)-*cp+(1<<rate-1) >> rate;
cp=&t[cxt+c0];
m.add(stretch(*cp>>4));
}
};
そして配列:
template <class T, int ALIGN=0> class Array {
private:
int n; // user size
int reserved; // actual size
char *ptr; // allocated memory, zeroed
T* data; // start of n elements of aligned data
void create(int i); // create with size i
public:
explicit Array(int i=0) {create(i);}
~Array();
T& operator[](int i) {
return data[i];
}
const T& operator[](int i) const {
return data[i];
}
int size() const {return n;}
void resize(int i); // change size to i
void pop_back() {if (n>0) --n;} // decrement size
void push_back(const T& x); // increment size, append x
private:
Array(const Array&); // no copy or assignment
Array& operator=(const Array&);
};