Reputation: 73
In an operator overloading function I am using another function that copys an array. But when i call the function arrayCopy() I receive an error stating:
Argument of type 'const char*' is incompatible with parameter of type 'char*'.
Any reasons and solution to fix this problem?
class InfinateInteger {
public:
InfinateInteger();
InfinateInteger(char c[]);
int* digitBreakDown(int c);
int digitLength(int c);
void intConversion(char stringArray[], int convertArray[], int size, int printQ);
void arrayCopy(char originalArray[], char copyArray[], int size);
const InfinateInteger operator +(const InfinateInteger& sec);
char * getIntString(); //getters
int getDigitL();
void setIntString(char newStr[]); //setters
void setDigitL(int length);
private:
char intString[1000000];
int posNeg = 1; //if pos ==1 if neg ==0
int digitL = 0;
};
const InfinateInteger InfinateInteger:: operator +(const InfinateInteger& sec) {
//function in which error is occurring
char str1[1000000];
arrayCopy(intString, str1, getDigitL());
char str2[1000000];
arrayCopy(sec.intString, str2, getDigitL()); //<--line where error occurs!!!!!
return InfinateInteger();
}
void InfinateInteger::arrayCopy(char originalArray[], char copyArray[], int size) {
for (int i = 0; i < size; i++) {
copyArray[i] = originalArray[i];
}
}
Upvotes: 2
Views: 11689
Reputation: 12047
The function that calls arrayCopy
is defined like this:
const InfinateInteger InfinateInteger:: operator +(const InfinateInteger& sec) {
You can see that sec
is qualified as const
, which means that also sec.intString
is const
.
arrayCopy
on the other hand is defined as
void InfinateInteger::arrayCopy(char originalArray[], char copyArray[], int size) {
originalArray
is not const
, this is why you get an error.
Change arrayCopy
to
void InfinateInteger::arrayCopy(const char originalArray[], char copyArray[], int size) {
Upvotes: 1