DoubleVoid
DoubleVoid

Reputation: 795

C++ class with public:ctor(), what does it mean?

I just stumbled upon this piece of code:

class MyClass
{
    public:MyClass();
        void             DoMagic();

    private:
        void             DoRealMagic();

    private:
        int              m_iSomething;
};

I wonder about this line:

public:MyClass();

What exactly does it mean and do?! I have never seen this before in C++ ... seems like it has something to do with the default ctor?!

Upvotes: 0

Views: 96

Answers (1)

πάντα ῥεῖ
πάντα ῥεῖ

Reputation: 1

You can write as well

 public:
      MyClass();

to make it clearer.

It's just a public default constructor declaration. No magic, nothing special.

I have never seen this before in C++ ...

Yes, it's very unusual to write it as seen. Proper line breaks and indentations are making the code much clearer to read.

Upvotes: 5

Related Questions