我简易实现了一个 vector。
然后我想利用它写一个高精度类,遇到了问题。
const int N=1;
template <typename T>
struct vector{
#define mslen sizeof(T)
T *q;
int tp=0,len,minn;
T& operator[](int idx){
return q[idx];
}
vector(int k=1){
q=new T[k];
minn=len=k;
}
void expand(bool t){
T *q2=new T[t?len<<1:len>>1];
memcpy(q2,q,mslen*tp);
delete [] q;
len=t?len<<1:len>>1;
q=q2;
}
void push(T x){
if(tp==len)expand(1);
q[tp++]=x;
}
bool pop(){
if(empty())return 0;
--tp;
if(tp<len>>1&&len>>1>=minn)expand(0);
return 1;
}
bool empty(){
return !tp;
}
int size(){
return tp;
}
int rsize(){
return len;
}
};
struct bigInt{
#define ull unsigned long long
vector<ull>a;
int b;
bigInt operator+(const bigInt&b)const{
vector<ull>tmp=a;
tmp.size();//可以使用
a.size();//使用会报错
}
};
int main(){
return 0;
}
能否通过某种方法使得a.size()可以正常使用,谢谢
报错信息为:'this' argument to member function 'size' has type 'const vector', but function is not marked constclang(member_function_call_bad_cvr)