From the course: C Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Constructors and destructors

Constructors and destructors - C Tutorial

From the course: C Essential Training

Constructors and destructors

- [Instructor] Constructors and destructors are special member functions that serve a specific purpose. Constructors are used to initialize and set up an object, and destructors are used to de-allocate and reset resources when an object is destroyed. There are several types of constructors in C . This is constructors.cpp from chapter seven of the exercise files, and you notice that this a bit longer. Our classes are going to start getting a little bit more complex from here on out. At the top, we include the string library because we're going to be using that and we have a using alias for std::string so we can just call it string from here on forward. We have two constants declared, and these are in static memory space because they're outside of any functions. Two constant strings. Unk stands for unknown and clone_prefix is a simple prefix string clone- and we'll see how we use that later. The interface to our…

Contents