I would like develop a credit card applicatoin for any MIPS based embedded device. I'm using mipsel-elf-g++ mix compiler. I implement an easy code as bellow.

    class A {
    public:
            virtual int getValue();
    }

    class B : public A {
    public:
            virtual int getValue();
    }

    int A::getValue() {
            return 1;
    }

    int B::getValue() {
            return 2;
    }

    int main() {

            A a1;
            B b1;
            A* a2 = &a1;
            B* b2 = &b1;

            int a_val_1 = a1.getValue();
            int b_val_1 = b1.getValue();

            int a_val_2 = a2->getValue();
            int b_val_2 = b2->getValue();

            return 0;
    }

a1.getValue() and b1.getValue() lines works effectively, however when all of a2->getValue() or b2->getValue() lines performed, I see segment fault message on screen. I believe among the OS, compiler or library maybe are damaged. I'm not sure the way i will find the issue.

what's wrong?

You've

B b1;

and u are asigning

B* b2 = &b2;

It ought to be

B* b2 = &b1;