# Managing Soundfile reader returned by createReaderFor

**URL:** <https://forum.juce.com/t/managing-soundfile-reader-returned-by-createreaderfor/37544>\
**Category:** General JUCE discussion\
**Created:** [February 10, 2020, 7:51am UTC](https://forum.juce.com/t/managing-soundfile-reader-returned-by-createreaderfor/37544 "2020-02-10T07:51:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sletz](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@sletz](https://forum.juce.com/u/sletz)\
**Post date:** [February 10, 2020, 7:51am UTC](https://forum.juce.com/t/managing-soundfile-reader-returned-by-createreaderfor/37544/1 "2020-02-10T07:51:15Z")

</div>

We have code written this way:

`ScopedPointer<AudioFormatReader> formatReader = fFormatManager.createReaderFor(File(path_name));`

that we want to rewrite using `unique_ptr` model, so:

`std::unique_ptr<AudioFormatReader> formatReader = std::make_unique<AudioFormatReader>(fFormatManager.createReaderFor(File(path_name)));`

which gives the following error when compiling : unimplemented pure virtual method ‘readSamples’ in ‘AudioFormatReader’  
virtual bool readSamples (int\*\* destChannels…)

What is the recommended way then to use `AudioFormatReader*` object returned by `createReaderFor` method ?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [February 10, 2020, 9:07am UTC](https://forum.juce.com/t/managing-soundfile-reader-returned-by-createreaderfor/37544/2 "2020-02-10T09:07:48Z")

</div>

The createReaderFor returns a raw pointer already, so you cannot use make\_unique (as you found out).  
Option one is to use `.reset (reader)` to let the unique\_ptr point to the new generated object (I don’t like that), or you create the unique\_ptr with the raw pointer as argument:

```auto
std::unique_ptr<AudioFormatReader> formatReader (fFormatManager.createReaderFor (File (path_name)));
// or for almost always auto fans:
auto formatReader = std::unique_ptr<AudioFormatReader>(fFormatManager.createReaderFor (File (path_name)));

```

Hope that helps

---

<div class="post-metadata">

**Author:** ![sletz](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@sletz](https://forum.juce.com/u/sletz)\
**Post date:** [February 10, 2020, 10:17am UTC](https://forum.juce.com/t/managing-soundfile-reader-returned-by-createreaderfor/37544/3 "2020-02-10T10:17:14Z")

</div>

Working, thanks.
