← Каталог
C++ - язык системного программирования — Добро пожаловать в мир C++
Фрагмент из «C++ - язык системного программирования»: Добро пожаловать в мир C++.
#include <iostream>
#include <string>
#include <memory>
class Greeting {
std::string message;
public:
explicit Greeting(std::string msg) : message(std::move(msg)) {}
void print() const { std::cout << message << '\n'; }
};
int main() {
auto hello = std::make_unique<Greeting>("Hello, C++!");
hello->print();
return 0;
} #include <iostream>
#include <string>
#include <memory>
class Greeting {
std::string message;
public:
explicit Greeting(std::string msg) : message(std::move(msg)) {}
void print() const { std::cout << message << '\n'; }
};
int main() {
auto hello = std::make_unique<Greeting>("Hello, C++!");
hello->print();
return 0;
}