Home » List of Companies » Apple C++ Interview Question

Apple C++ Interview Questions


#include<iostream>
#include<memory>

using namespace std;

class CPU
{
public:
    CPU() { operation1(); }
    ~CPU() { cout<<"~CPU"<<endl; }
    virtual void operation1() { cout<<"beep"<<endl; }
    virtual void operation2() { operation1(); }
    
};

class UpdatedCPU: public CPU
{
public:
    ~UpdatedCPU() { cout<<"~UpdatedCPU" << endl; }
    void operation1() override { cout<<"bLip"<<endl; }
    virtual void operation3() { operation2(); }
};

void SomeRoutine(CPU chip)
{
    chip.operation1();
    chip.operation2();
}

int main()
{
    UpdatedCPU chip;
    chip.operation1();
    chip.operation2();
    chip.operation3();
    
    {
        std::unique_ptr<CPU> chip2 = make_unique<UpdatedCPU>();
        SomeRoutine(*chip2);
    }
    
    return 0;
}

Output of above C++ program

Apple C++ Interview Questions