-3

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

Mat
  • 202,337
  • 40
  • 393
  • 406
Af'faq
  • 501
  • 3
  • 13
  • 28

1 Answers1

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