jeudi 1 août 2019

faulty code with lots of errors, find the faulty code(s)

So i have an exam and one of the tasks is to identify the faults and syntax errors in the code. This is the part that i am struggling the most with and i was wondering if i could ask for help here.

So basically we're given a code and we need to point out the errors and bad code. Unfortunately there is no blueprint and that is why i am asking here.

the code: https://godbolt.org/z/XbuPP1

classA {
    public:
    A(intid);
    voidprint();
    private:intid;
};


classB : publicA{
    public:
    B(intid);
    voidprint();
};

intmain(){
    A* arr[2];arr[0] = newA(1);arr[1] = newB(2);
    arr[0]->print();arr[1]->print();
    keep_window_open();
    return0;
}

A::A(intid) {
    id= id;
}

B::B(intid) : A(id) {}

voidA::print() {
    cout "Jeg er av klasse A og har id "<< id;
}

voidB::pint(){
    cout << "Jeg er av klasse B og har id "<< id;
}

Aucun commentaire:

Enregistrer un commentaire