Use of colon after class name in c++
Asked Answered
J

3

28

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?

Justificatory answered 11/11, 2013 at 4:38 Comment(0)
M
42

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.

Medlock answered 11/11, 2013 at 4:40 Comment(3)
so, is that colon another name for extend keyword?Knowle
No it's not, because there is no such keyword in C++.Medlock
oh, it seems that I confused it with java. and it also supposed to be extends instead.Knowle
S
6

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

Scilla answered 11/11, 2013 at 4:40 Comment(0)
M
1

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;

    }
}

}
Machellemachete answered 4/3, 2016 at 4:8 Comment(1)
Just a inheritance from the class1 to class 2 in simple way of doing it, i hope it helps some one!Machellemachete

© 2022 - 2024 — McMap. All rights reserved.