C++ 在作用域中声明向量
在我正在进行的BigInt类中,我在向量声明方面遇到了问题。我得到的错误是: prog.cpp:在函数“void setBig1(std::string,int)”中: prog.cpp:45:3:错误:“big1”未在此范围内声明C++ 在作用域中声明向量,c++,vector,C++,Vector,在我正在进行的BigInt类中,我在向量声明方面遇到了问题。我得到的错误是: prog.cpp:在函数“void setBig1(std::string,int)”中: prog.cpp:45:3:错误:“big1”未在此范围内声明 big1.推回(dig[x]) ^ prog.cpp:在函数“voidgetBig1(int)”中: prog.cpp:50:11:错误:“big1”未在此范围内声明 cout您忘了指定定义成员函数的类。而不是 void setBig1(string dig, in
big1.推回(dig[x])
^ prog.cpp:在函数“voidgetBig1(int)”中: prog.cpp:50:11:错误:“big1”未在此范围内声明
cout您忘了指定定义成员函数的类。而不是
void setBig1(string dig, int dLength){
for(int x= 0; x<(dLength); x++)
{
big1.push_back(dig[x]);
}
}
void getBig1(int dLength){
for(int x= 0; x<(dLength); x++){
cout << big1[x] ;
}
void setBig1(字符串dig,整数长度){
对于成员函数定义上的(int x=0;xMissingbigInt::
)。big1是bigInt的成员。您仍然需要bigInt的实例才能访问它。您不能直接从类外部访问它。添加const
后缀的加1的副本。
void setBig1(string dig, int dLength){
for(int x= 0; x<(dLength); x++)
{
big1.push_back(dig[x]);
}
}
void getBig1(int dLength){
for(int x= 0; x<(dLength); x++){
cout << big1[x] ;
}
void bigInt::setBig1(string dig, int dLength){
for(int x= 0; x<(dLength); x++)
{
big1.push_back(dig[x]);
}
}
void bigInt::getBig1(int dLength){
for(int x= 0; x<(dLength); x++){
cout << big1[x] ;
}
class bigInt
{
//...
void getBig1(int dLength) const;
};
void bigInt::getBig1(int dLength) const
{
for ( int i = 0; i < dLength; i++ ) cout << big1[i] ;
}