c++面试题

#include <QtGui/QApplication>

#include "mainwindow.h"

#include <QMessagebox>

class CB{

public:

    virtual void OutString(const char* str="CB:Outstring")

    {

     QMessageBox::information(NULL, "EnQStrXml", "Call CB::Outstring(...)");

     QMessageBox::information(NULL, "EnQStrXml", str);

    }

};

class CD:public CB{

public:

    virtual void OutString(const char* str="CD:Outstring")

    {

     QMessageBox::information(NULL, "EnQStrXml", "Call CD::Outstring(...)");

      QMessageBox::information(NULL, "EnQStrXml", str);

    }

};

void TestOutString(CB& cb)

{

cb.OutString();

}

int main(int argc, char *argv[])

{

    QApplication a(argc, argv);

   // MainWindow w;

    //w.show();

    CB cbobj;

    CD cdobj;

    cbobj.OutString(); //Call CB::Outstring(...)   CB:Outstring

    cdobj.OutString();//Call CD::Outstring(...)   CD:Outstring

    cbobj.OutString("Hello World");//Call CB::Outstring(...)   Hello World

    cdobj.OutString("welcome to cnit");//Call CB::Outstring(...)   welcome to cnit

    TestOutString(cbobj);// Call CB::Outstring(...)   CB:Outstring

    TestOutString(cdobj);// Call CD::Outstring(...)   CB:Outstring

 

    return a.exec();

}


你可能感兴趣的:(C++)