I'm trying to make a runtime id for an object. I have it done using a regular pointer, but I need to make it work with a unique pointer. Why can't I use new
in the unique pointer? I get
Error E0079 expected a type specifier.
On this line:
unique_ptr<char> idPtr(new char[DEVICE_ID_LENGTH]);
Here is the full file:
#pragma once
#include <iostream>
#include <string>
#include <memory>
#include <utility>
using namespace std;
constexpr auto DEVICE_ID_LENGTH = 10;
class Widget
{
public:
//constructor
explicit Widget(int nbr);
~Widget();
void getID(char* s, const int len);
std::string WhatIAm;
//char* idPtr = new char[DEVICE_ID_LENGTH]; //This needs to be initialized by the constructor
unique_ptr<char> idPtr(new char[DEVICE_ID_LENGTH]);
int getSize();
private:
int widgetSize;
int widgetNumber;
};