Answers for "unique ptr c++"

C++
1

unique ptr c++

#include <iostream>
#include <memory>
using namespace std;
int main(int argc, const char **argv) {
  unique_ptr<int> num_ptr = make_unique<int>(5);
  cout << *num_ptr << endl;
  return 0;
}
Posted by: Guest on October-17-2021
2

unique_ptr in c++

#include <iostream>
class Entity {
public:
	int b = 0;
	Entity() { std::cout << "[CREATED ENTITY]" << std::endl; };
	~Entity() { std::cout << "[Destroyed ENTITY]" << std::endl; };
	void Print() {};
};
int main()
{

	{
		std::unique_ptr<Entity> entity = std::make_unique<Entity>();
		//std::unique_ptr<Entity> entity1 = entity;//can't copy
		
		entity->Print();
		
	}

}
Posted by: Guest on August-10-2020

Browse Popular Code Answers by Language