Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created May 3, 2024 08:37
Show Gist options
  • Save velotiotech/dcd895920cad2b3d2855741f6dd686d8 to your computer and use it in GitHub Desktop.
Save velotiotech/dcd895920cad2b3d2855741f6dd686d8 to your computer and use it in GitHub Desktop.
class numbers {
private:
std::vector<std::unique_ptr<int>> numbers;
public:
void addNumber(int value)
{
std::unique_ptr<int> ptr(new int(value));
numbers.push_back(ptr);
}
void printNumbers()
{
for (const auto& ptr : numbers) {
std::cout << *ptr << " ";
}
}
};
int main()
{
numbers n;
n.addNumber(10);
n.addNumber(20);
n.printNumbers();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment