Suppose you have to develop an application for XYZ bank with the following features. 1)The application must be secure 2)For transactions, proper interfaces will be provided to the customers. 3)The application must be reusable. 4)The application must be efficient in terms of speed and memory usage. You can use either structs or class in order to achieve the above mentioned features. So which programming construct (class or struct) will you select for application development. Please help me out here. Thanks
Asked
Active
Viewed 298 times
-3
-
3Makes absolutely no difference, except the public vs private default. – Mat Aug 11 '18 at 07:01
-
Which will be more efficient for such type of scenario? And why? – Af'faq Aug 11 '18 at 07:02
-
Notice that StackOverflow is not a *do-my-homework* site – Basile Starynkevitch Aug 11 '18 at 07:10
-
1some people might have a vague convention of using structs for POD types and classes for everything else but its not set in stone – Alan Birtles Aug 11 '18 at 08:06
-
c++ does not have structs and classes. c++ has only classes that can be declared with the keywords `struct` / `class` – 463035818_is_not_an_ai Aug 11 '18 at 10:10
1 Answers
3
struct
and class
are nearly equivalent in C++ (you can have member functions, constructors & destructors, data members in both). More precisely,
struct Sometype {
/// some code here
};
is equivalent to
class Sometype {
public:
/// some code here
};
So the runtime efficiency is the same (since public:
is an annotation for the compiler which is lost, as most type information, at runtime; be aware of type erasure).
You really should take days to read some good book about C++ programming, then look into some C++ reference site, then read (or at least refer to) some C++ standard like n3337 (for C++11; for later standards, find them by yourself).
Learn about the rule of five and about standard containers and smart pointers.

Basile Starynkevitch
- 223,805
- 18
- 296
- 547