Monday, February 11, 2019

Structs Vs Classes

Simply put structs and classes are the same except for one factor, which is, that all member variables and functions are public by default. This can be extremely useful. Below is an example of what a struct might look like and what a class might look like.

Struct Example

struct SomeStruct
{
    int someIntVariable;
    std::string someStringVariable;

    void SomeFunction();
}

Class Example

class SomeClass
{
public:
    SomeClass();
    ~SomeClass();

    void SomeFunction();
    int GetSomeIntVariable() { return someIntVariable; };

private:
    int someIntVariable;
}

No comments:

Post a Comment