Memory issues when I am trying to upcast


I get a memory error when I am trying to make a base pointer point to a derived object. I know how to fix it, but I would like to find out why it doesn't work like this. I know *bp = d_ob is not the same as bp = &d_ob which work, but where am I wrong ?

#include <iostream>

using namespace std;

class Base { public:
    virtual void f()
        cout << "Inside Base\n";
class Derived : public Base {
    void f()
        cout << "Inside Derived\n";

int main() {
    Base *bp, b_ob;
    Derived *dp, d_ob;

    *bp = d_ob; 

    return 0;


The error I get is Process returned -1073741819 (0xC0000005)

asked on Stack Overflow May 23, 2021 by miha

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0