I do not understand why line 21 is ok but line 25 is error?
The error message:
invalid conversion from 'const int*' to 'int*' [-fpermissive]
Push is function in class that decleared like this:
template< typename Type >
class Stack {
void Push(const Type& value) {
SNode* type = new SNode();
if (this->head != nullptr) {
this->head->up = temp;
}
temp->value = value;
temp->up = nullptr;
temp->down = head;
temp->head = temp;
num_of_elements++;
}
};
int main() {
Stack<int*>* stk = new Stack<int*>();
int a = 5;
int* x = &a;
stk->Push(x); //this line is fine
const int b = 5;
const int* y = &b;
stk->Push(y); //this line is an error
delete stk;
return 0;
}
It's look like function Push get parameter from type of "const int * &
" , and in line 25 , i exactly sends a const pointer "const int *
". so what is the problem?