C++ Standard Template Library (STL) provides the data structure, Vector, that represents a dynamic array internally. As the vector is a template class, it can represent an array of virtually any data type. Here we’ll see how the Vector can represent an integer array. The vector data structure has many advantages over a traditional array. … Continue reading “C++ | Vector, the Dynamic Array”
Tag: C++
C++ | Roman to Decimal Conversion
Roman numerals are a number system that was originated from ancient Rome. Even though it is sort of obsolete, we often come across Roman numerals in various places. They are often used in movie titles, monarch names, chemistry periodic tables, sporting events among others. Sometimes it is difficult to read, especially the big numbers, for … Continue reading “C++ | Roman to Decimal Conversion”
Function Overloading in C++
Function overloading in C++ allows us having multiple definitions of a single function or method. That means that we can have multiple functions with same name. But their input arguments need to be different, either in data type or number of arguments. In time of calling the function, the compiler decides which function to call … Continue reading “Function Overloading in C++”
Singleton Class in C++
Singleton class ensures that there will be only one object of the class in lifetime of a program. Normally we can create as many objects as we want from a particular class. But you’ll be able to create at most one object from a singleton class. Where to Use Singleton Class? There are situations where … Continue reading “Singleton Class in C++”
What is std::shared_ptr? Examples
std::shared_ptr is a smart pointer that manages shared ownership of an object through pointer. Multiple std::shared_ptr (s) can hold the same object pointer. The actual object gets deleted when all the std::shared_ptr (s) go out of scope or get deleted/reset. It was introduced in C++11. It helps C++ programmers cleaning up memory in very convenient … Continue reading “What is std::shared_ptr? Examples”