Software & Finance





C++ - Struct





You can have multiple data members of various types in C Language structures. In C++, you can have both data members and function. Actually there is no difference between strcut and class in C++ except all the members declared in struct are public by default whereas in class it is private.

Three access levels are,

1. Private - Can be accessed only by the members of the struct or class
2. Protected - Can be accessed by the struct and its derived struct  or class
3. public - Can be accessed by any other struct  or class or function.

struct MyClass

{

    int m; // By default variables and functions are public
    
int TestFunc1();

 

private:

private: 

    int a;

    int b;


public
:

    MyClass() : a(10), b(20), m(30)

    {

    };

};