C++: pure virtual method called — terminate called without an active exception
A pure virtual function was called on an object that is being constructed or destroyed, where the derived part no longer exists.
pure virtual method calledundefined reference to `__cxa_pure_virtual'pure virtual function calledR6025 pure virtual function call Meaning
During a base-class constructor or destructor the object's dynamic type is the base, so a virtual call resolves to the base version — which is pure and has no body. The same happens when another thread calls a method on an object that is mid-destruction, or after the object has been deleted.
Common causes
- Calling a virtual function from a base-class constructor or destructor
- Object used after
delete(dangling pointer) - Thread calling methods while the object is destroyed
- Slicing a derived object to its base
⚡ Quick fix
- Don't call virtual functions from constructors and destructors
- Use a separate
init()step or a factory function after construction - Make the destructor
virtualand manage lifetime with smart pointers
Detailed fix by platform
C++
- Move the virtual call out of the constructor into a named
start()method called after construction - Use
std::shared_ptr/std::weak_ptrwhen another thread needs the object
Code examples
The trap
struct Base {
Base() { setup(); } // calls Base::setup (pure!) during construction
virtual void setup() = 0;
virtual ~Base() = default;
};
struct Derived : Base {
void setup() override {}
};
// Derived d; -> "pure virtual method called" / terminate
// Fix: call setup() after construction, e.g. Derived d; d.setup();How to diagnose
- Context — Called from a constructor or destructor?
- Lifetime — Could the object already be deleted?
- Threads — Another thread using it?
🔧 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
- AddressSanitizer: heap-buffer-overflow C/C++: ==ERROR: AddressSanitizer: heap-buffer-overflow on address — READ/WRITE of size N
- AddressSanitizer: heap-use-after-free C/C++: ==ERROR: AddressSanitizer: heap-use-after-free on address — memory used after delete/free
- Assertion failed C/C++: Assertion `x > 0' failed. Aborted (core dumped) — assert() condition was false
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