Structure in c plus plus

1 answer

Answer

1018590

2026-08-03 12:30

+ Follow

Structures are the same as classes in C++. The only difference is that structure members are public by default while class members are private by default, but both define a class of object and both are initialised via a class constructor initialisation list.

struct my_object

{

my_object(const int data): m_data(data) {}

private:

int m_data;

};

The above struct is no different to the following class:

class my_object

{

int m_data;

public:

my_object(const int data): m_data(data) {}

};

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.