Using auto and unique_ptr - building using Visual Studio 2019

I have started building my plugins for Windows using Visual Studio 2019, however have encountered numerous errors. One such error was related to the deprecated ScopedPointer, however I simply replaced any declarations with auto and that resolved the errors. However I have a function that reads the resulting unique_ptr into a Drawable using Drawable::createFromSVG. I also used auto here to resolve another issue where the output from this function was not a raw Drawable* but instead was a unique_ptr, however this created complications when trying to use the DrawableButton::setImages function because it takes a Drawable*.

Not sure what to do - has anyone else solved this?

    static auto getDrawable(const String& binaryData, Colour inColor, Colour outColor, float scaleFactor = 1.0f){

    // Load active on svg
    auto svg(XmlDocument::parse(binaryData));
    jassert(svg != nullptr);
    //changeColor(svg, inColorHex, outColorHex);
    auto drawable = Drawable::createFromSVG(*svg);
    drawable->replaceColour (inColor , outColor);
    drawable->setTransform(AffineTransform::scale(scaleFactor));
    
    return drawable;
}

you can get the pointer owned by the unique_ptr via the unique_ptr<>::get member function:

https://en.cppreference.com/w/cpp/memory/unique_ptr/get

auto svg = XmlDocument::parse(binaryData);
auto drawable = Drawable::createFromSVG(*svg);
DrawableButton myButton;
myButton.setImages( drawable.get() );
3 Likes