Junior — Middle
What tools and constructs of C++ language have you used in your practice?
sobes.tech AI
Answer from AI
In practice, the following tools and constructs are often used in C++:
- Classes and objects for modeling entities.
- Constructors and destructors for managing the lifecycle of objects.
- Encapsulation using access modifiers (private, protected, public).
- Inheritance and polymorphism to extend functionality.
- Templates for creating generic functions and classes.
- Exceptions (try-catch) for error handling.
- Standard Library (STL): containers (vector, map, set), algorithms, iterators.
- Smart pointers (std::unique_ptr, std::shared_ptr) for memory management.
- Lambda expressions for convenient function passing.
Example of using a template and a smart pointer:
#include <iostream>
#include <memory>
template<typename T>
void printValue(const T& value) {
std::cout << value << std::endl;
}
int main() {
std::unique_ptr<int> ptr = std::make_unique<int>(42);
printValue(*ptr);
return 0;
}