Avatar ·

When to use class and when to use struct in C++? Understanding the key differences

Hello everyone! I'm learning C++ and I can't figure out in which cases I should use class and in which struct. They seem syntactically almost the same, but I've read that there is a difference in default member access between them. For example, I wrote this struct for storing point coordinates:\n\n```cpp\nstruct Point {\n int x;\n int y;\n};\n```\n\nAnd this class for a point:\n\n```cpp\nclass PointClass {\n int x;\n int y;\npublic:\n PointClass(int x, int y) : x(x), y(y) {}\n};\n```\n\nI use them like this:\n\n```cpp\nPoint p1 = {10, 20}; // works\nPointClass p2(10, 20); // works\n```\n\nBut when I tried to do something similar with a class where I wanted to store some data and methods, I got confused. I've heard opinions that struct is for simple data, and class is for