I am a self-learner of C++, currently, I know some previous programming languages well, but never got into classes. The book I'm reading about C++ - 1214 pages - talks very unclearly and shortly about classes, so I don't really get it. I hope you give an advanced explanation, giving the official terms of everything,
telling me the why behind things. Also consider I already know this:
I have already studiedstructs; I think it's just a struct with private, public and protected members and it can also have member functions?
I'm also totally lost out on constructors and destructors, and don't have a clue about ADT or Abstract Data Type (what the hell is that?)... Note
Please avoid "Google it" answers because my case is very specific. I also want practical advice to the use of classes... Other than user-defined header files?
std::string is an abstract data type. An ADT is just a data type created using the basic data types: bool, char, int, and float. std::string is an array of chars.
A constructor is a function that initializes your class and a destructor is a function that deletes your class.
class example
{
public:
example(); // constructor
~example ( ); // destructor
// other class functions would go here
private:
int value;
};
example::example ( ) // this function is called whenever someone creates an object of this class
{
value = 5; // initialize our value to 5
}
example::~example ( ) // this function is called whenever an object of this class goes out of scope
{
// since an int is a basic data type, we don't have to do anything here
}
Thanks, now I get it... But what is so special about a class if structs also have private and protected members too. And can have member functions and constructors/destructors. Inheritance and composition??! That's all the fuss about classes?