#include <iostream>
#include <memory>
using namespace std;
struct buffer{
int buffFilled;
};
struct verifyStruct{
int capacity;
int size;
std::shared_ptr<buffer[]> element;
};
int main()
{
verifyStruct stVerify;
stVerify.capacity = 10;
stVerify.size = 10;
stVerify.element = new buffer[10]; //Throws compilation error.
return 0;
}
How to fill stVerify.element? Is there anyway to create using make_shared. Please help.
With C++20, you can initialize a shared_ptr to an array with:
Without C++20, you can use
newandcustom deleter. Example: