Use of colon after class name in c++

人走茶凉 提交于 2019-11-30 11:55:45

问题


This is a header file extracted from a blackberry 10 helloworld program.

#ifndef ApplicationUI_HPP_
#define ApplicationUI_HPP_

#include <QObject>

namespace bb
{
    namespace cascades
    {
        class Application;
        class LocaleHandler;
    }
}

class QTranslator;

/*!
 * @brief Application object
 *
 *
 */

class ApplicationUI : public QObject
{
    Q_OBJECT
public:
    ApplicationUI(bb::cascades::Application *app);
    virtual ~ApplicationUI() { }
private slots:
    void onSystemLanguageChanged();
private:
    QTranslator* m_pTranslator;
    bb::cascades::LocaleHandler* m_pLocaleHandler;
};

#endif /* ApplicationUI_HPP_ */

I am confused about the colon operator right after the class name declaration.

class ApplicationUI : public QObject

What does this mean?


回答1:


It means that ApplicationUI inherits all methods and member variables from the class QObject. The use of public means that the public methods and members of QObject are also public in ApplicationUI.




回答2:


The class listed after the : is what the class ApplicationUI inherits from.




回答3:


Simple code snippet here:

using System;

namespace ProgramCall
{

class Class1
{

    public int Sum(int A, int B)
    {
        return A + B;
    }

    public float Sum(int A, float B)
    {
        return A + B;
    }
}

class Class2 : Class1
{
    public int Sum(int A, int B, int C)
    {
        return A + B + C;

    }
}

}


来源:https://stackoverflow.com/questions/19898920/use-of-colon-after-class-name-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!