0

I am not really firm with C++ yet and learning by reading example code. I now found a class declaration, that has member variables outside the access specifiers public and private.

class Card {
    friend class FortyApp;

    static double m_scale;
    static int m_width,m_height;

public:
    Card(int value, WayUp way_up = facedown);
    virtual ~Card(){};

    void Draw(wxDC& pDC, int x, int y);
    static void DrawNullCard(wxDC& pDC, int x, int y); // Draw card place-holder
    void Erase(wxDC& pDC, int x, int y);

    void TurnCard(WayUp way_up = faceup) { m_wayUp = way_up; }
    WayUp GetWayUp() const { return m_wayUp; }
    int GetPipValue() const { return m_pipValue; }
    Suit GetSuit() const { return m_suit; }
    SuitColour GetColour() const { return m_colour; }
    static void SetScale(double scale);
    static int GetHeight() { return m_height; };
    static int GetWidth() { return m_width; };
    static double GetScale() { return m_scale; };

private:
    Suit m_suit;
    int m_pipValue; // in the range 1 (Ace) to 13 (King)
    SuitColour m_colour; // red or black
    bool m_status;
    WayUp m_wayUp;

    static wxBitmap* m_symbolBmap;
    static wxBitmap* m_pictureBmap;
};

I don't understand if this has a higher reason. The variables m_scale, m_width and m_height are now private, as it is standard, or?

Thanks in advance.

DermotA
  • 3
  • 2
  • 3
    You can find the answer to that and more [here](https://stackoverflow.com/a/388282/3484570). – nwp Jan 15 '18 at 13:44
  • 6
    A class is private until you say otherwise. A struct is public until you say otherwise – doctorlove Jan 15 '18 at 13:45
  • learning c++ by reading code only isnt the best idea btw – 463035818_is_not_an_ai Jan 15 '18 at 13:45
  • Possible duplicate of [C++: Can a struct inherit from a class?](https://stackoverflow.com/questions/3574040/c-can-a-struct-inherit-from-a-class) – doctorlove Jan 15 '18 at 13:46
  • They are not outside of access specifier, they are under effect of the last access specifier. Though it is a good practice to write access specifier for each member. – user7860670 Jan 15 '18 at 13:46
  • C++ is so rich in options, that as a beginner it is hard to distinguish if a thing like this has a higher meaning or is bad programming style. I could not answer my question via google. – DermotA Jan 17 '18 at 07:48

1 Answers1

0

do you know the default access specifier is ?

it is private.

if you don't provide any access specifier it will be automatically set to private .

if you want to M_scale to be public declare it inside public:

jasinth premkumar
  • 1,430
  • 1
  • 12
  • 22