Returning a std::unique_ptr

  c++, unique-ptr

It is okay for a private std::unique_ptr member of a class to be retrieved as
a raw pointer via get()?

Example class:

class png {
public:
    png(const std::string& fname);
    png(const png&);
    png();

    png& operator=(png);

    ~png();

    void read(const std::string& fname);

    inline bool is_valid() {
        return m_val;
    }

    const unsigned char* getData() const;

private:
        std::unique_ptr<char> m_data;  // m_data is its image data

Retrieval function

const unsigned char* png::getData() const
{
    return m_data.get();
}

Source: Windows Questions C++

LEAVE A COMMENT