Basically, is it acceptable programming practice/style to call a constructor of a class within its overloaded assignment operator? If not, why not?
EXAMPLE:
so I have a class which has 3 data members, a dynamic int array called "value" which holds digits of a large number, an int length
which indicates the number of digits in the number, & an int maxLength
which indicates the max length of the number (size of the dynamic array)
here's my constructor with param int:
bigInt::bigInt(const int &rhs){
//turn num_ into a string 'num'
stringstream ss;
ss << num_;
string num = ss.str();
length = strlen(num.c_str());
maxLength = (length - (length%16)) + 16;
value = new int[maxLength];
for(int i=1; i<=length; i++){
value[i-1] = num.at(length-i) - '0';
}
}
and here's my overloaded assignment operator in which the righthand side is a regular int this method calls the constructor:
bigInt bigInt::operator=(const int &rhs){
*this = bigInt(rhs);
return *this;
}
EDIT: I guess I should have worded it differently. I didn't mean COPY constructor, but rather a regular constructor with non-class-instance parameter, and an overloaded assignment operator in which the rhs isn't the same type as the lys