In my In-Progress BigInt class, I am having trouble with the declaration of vectors. I am getting the errors:
prog.cpp: In function 'void setBig1(std::string, int)': prog.cpp:45:3: error: 'big1' was not declared in this scope
big1.push_back(dig[x]);
^prog.cpp: In function 'voidgetBig1(int)': prog.cpp:50:11: error: 'big1' was not declared in this scope
cout << big1[x] ;
I believe that my getters and setters involved with the vector big1 are not recognizing the decleration of the vector in the 'public:' portion of the class definition. But I cannot find a solution or a definite reason for the errors. My code is Below:
//my bigInt class
#include <iostream>
#include <vector>
#include <string>
using namespace std;
//class, constructors
//overload operators methods
//add, subtract, multiply, divide
class bigInt{//class
public:
bigInt();
~bigInt();
void setString(string dig);
string getString(void);
int getDigitLength(void);
std::string digit;
int digitLength;
std::string digString;
void setBig1(string dig, int dLength);
std::vector<int> big1;
std::vector<int> big2;
void getBig1(int dLength);
};
//constructors
bigInt::bigInt(void){
std::vector<int> big1;
}
//deconstructor
bigInt::~bigInt(){
}
//getters/setters
void bigInt::setString(string dig){
digit= dig;
digitLength= (digit.length());
}
string bigInt::getString(){
return digit;
}
int bigInt::getDigitLength(){
return digitLength;
}
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] ;
}
}
int main(){
string digString= "1"; //string
bigInt my_int{};
//bigInt big1<int>;
my_int.setString(digString); //setInternalString to equal digString
cout << my_int.getString() << endl; //prints internal string
my_int.setBig1(my_int.getString(), my_int.getDigitLength());//sets big1 vector = to string
my_int.getBig1(my_int.getDigitLength()); //print big1 vector
}
I greatly appreciate any assistance.
bigInt::
on member function definitions. – hmjd