C++: error: passing 'const X' as 'this' argument discards qualifiers [-fpermissive]
A const object (or const reference) is calling a method that is not declared const, which could modify it.
discards qualifierspassing 'const' as 'this' argument discards qualifierserror: binding reference of type to discards qualifierscannot bind non-const lvalue referenceno viable function (candidate function not viable: 'this' argument has type 'const Meaning
Calling obj.method() on a const Obj& is only allowed if method() is marked const. Mark every method that does not change the object const; that is also what makes them usable from const references and in containers.
Common causes
- Member function that only reads data is not declared
const - Const reference or pointer parameter calling a non-const method
- Range-for over a const container using non-const methods
operator[]orbegin()without a const overload
⚡ Quick fix
- Add
constafter the parameter list:int size() const; - Change
T&toconst T&only if the method truly does not modify - Provide both const and non-const overloads when needed
Detailed fix by platform
C++
- Declare read-only methods as
int size() const { return n_; } - If it caches data, mark the cache
mutable
Code examples
Make read-only methods const
struct Stack {
int top() const { return v[n - 1]; } // const: only reads
void push(int x) { v[n++] = x; } // modifies, so non-const
int v[16]; int n = 0;
};
void print(const Stack& s) {
s.top(); // OK
// s.push(1); // error: passing 'const Stack' as 'this' argument discards qualifiers
}How to diagnose
- Object — Is the object const?
- Method — Is the called method declared const?
- Intent — Does the method modify state?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- call of overloaded is ambiguous C++: error: call of overloaded 'f(int)' is ambiguous
- cannot declare variable to be of abstract type C++: error: cannot declare variable 'x' to be of abstract type 'Shape' (pure virtual functions)
- incomplete type C++: error: invalid use of incomplete type 'class X' — forward declaration only
Most viewed in C/C++
- terminate called after throwing an instance of C++: terminate called after throwing an instance of 'std::out_of_range' — what(): vector::_M_range_check
- double free or corruption C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped)
- undefined reference to C/C++: undefined reference to `function' — collect2: error: ld returned 1 exit status
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 15 Oct 2026