1

Recently I was seeing one github project written in C++ that define objects with structs.

Example:

struct Example
{
    std::string message;

    Example() 
    {
        message = "foo";
    }

    void setMessage(std::string newMsg)
    {
        message = newMsg;
    }

    void getMessage(std::string newMsg)
    {
        return message;
    }
}

In researches, I found a definition of the difference between define object with struct and class, is: in struct, methods, functions, and attributes are public by default, in class the same are private by default.

My questions are: What are the benefits to use structs than classes?

Isdeniel
  • 196
  • 10

0 Answers0