Error C2664

Hi all,

I’ve followed this tutorial to update my Hello World-esque gain VST from using the now deprecated ScopedPointer to std::uniqe_ptr However, I’ve got a silly error that I can’t seem to figure out for my first big hurdle as a learner.

I’ve narrowed it down to the following line

    mGainValue =
    std::make_unique<AudioProcessorValueTreeState::SliderAttachment>
    (new AudioProcessorValueTreeState::SliderAttachment(p.getAPVTS(), "gain", mGainSlider));    

The error is here

Severity Code Description Project File Line Suppression State
Error C2664 ‘juce::AudioProcessorValueTreeState::SliderAttachment::SliderAttachment(const juce::AudioProcessorValueTreeState::SliderAttachment &)’: cannot convert argument 1 from ‘_Ty’ to ‘const juce::AudioProcessorValueTreeState::SliderAttachment &’ Hard Gainer_SharedCode C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\memory 2064

While I understand that there is a type mismatch, I don’t understand why I am receiving it or how to proceed. The guides I have seen do not have different code. So, please, if anyone could shed some light on how I’m being an idiot, I’d be most appreciative.

make_unique calls new itself internally, so it’s not needed in the call itself :

mGainValue = std::make_unique<AudioProcessorValueTreeState::SliderAttachment> (p.getAPVTS(), "gain", mGainSlider);

1 Like

Thanks for the reply. However, removing the new keyword hasn’t fixed the error. It has been five days now that I have been stuck with this error and I cannot see how to resolve it. Do you have any idea what may be causing this issue?

@ilikesupernoodles we can’t help you without knowing more about your code. Which exact version of JUCE are you using? What is the type of mGainValue? Does p.getAPVTS() return an AudioProcessorValueTreeState& as expected?

The error that you shared in your first post is also incomplete. It mentions _Ty, but it doesn’t say what _Ty is.

I’m using Juce 5.4.7.

The mGainValue created as so

std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment> mGainValue;

and the getAPVTS method is from the attached tutorial. It returns the mAPVTS variable.

public: 
    AudioProcessorValueTreeState& getAPVTS() { return mAPVTS; };
private:   
     AudioProcessorValueTreeState mAPVTS;

I can assure you that was the complete error, copy/pasted straight from Visual Studio’s output. :slight_smile:

I haven’t changed any code since removing the new keyword, but the errors that appear on a clean build are now different. C2280 and C2248. All I have done since is close Projucer/Visual Studio and reboot my workstation.

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2280	'juce::AudioProcessorValueTreeState::SliderAttachment::SliderAttachment(const juce::AudioProcessorValueTreeState::SliderAttachment &)': attempting to reference a deleted function (compiling source file ..\..\Source\PluginEditor.cpp)	Hard Gainer_SharedCode	C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\memory	2064	

and

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2248	'juce::AudioProcessorValueTreeState::SliderAttachment::SliderAttachment': cannot access private member declared in class 'juce::AudioProcessorValueTreeState::SliderAttachment' (compiling source file ..\..\Source\PluginEditor.cpp)	Hard Gainer_SharedCode	C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\memory	2063	

Double clicking either error takes me to this function inside a file called “Memory”

// FUNCTION TEMPLATE make_unique
template <class _Ty, class... _Types, enable_if_t<!is_array_v<_Ty>, int> = 0>
_NODISCARD unique_ptr<_Ty> make_unique(_Types&&... _Args) { // make a unique_ptr
    return unique_ptr<_Ty>(new _Ty(_STD forward<_Types>(_Args)...));
}

If there is any other information I can provide that will help, let me know.

What you copy-pasted comes from the “Error List” view of Visual Studio, which contains a single line per error/warning. In the “Output” view (after making sure that it reads Show output from: Build in the top-left corner), you usually have more details about the error/warning. Please provide errors/warnings with all details.

Could you please copy-paste your current version of the code that fails to compile? Maybe you didn’t apply @Xenakios’ suggestion properly.

1>------ Build started: Project: Hard Gainer_SharedCode, Configuration: Debug x64 ------
1>PluginProcessor.cpp
1>PluginEditor.cpp
1>D:\Hard Gainer\Source\PluginProcessor.cpp(84,55): warning C4100: 'index': unreferenced formal parameter
1>D:\Hard Gainer\Source\PluginProcessor.cpp(88,60): warning C4100: 'index': unreferenced formal parameter
1>D:\Hard Gainer\Source\PluginProcessor.cpp(93,76): warning C4100: 'newName': unreferenced formal parameter
1>D:\Hard Gainer\Source\PluginProcessor.cpp(93,55): warning C4100: 'index': unreferenced formal parameter
1>D:\Hard Gainer\Source\PluginProcessor.cpp(98,70): warning C4100: 'samplesPerBlock': unreferenced formal parameter
1>D:\Hard Gainer\Source\PluginProcessor.cpp(98,54): warning C4100: 'sampleRate': unreferenced formal parameter
1>D:\Hard Gainer\Source\PluginProcessor.cpp(150,86): warning C4100: 'midiMessages': unreferenced formal parameter
1>D:\Hard Gainer\Source\PluginProcessor.cpp(194,66): warning C4100: 'destData': unreferenced formal parameter
1>D:\Hard Gainer\Source\PluginProcessor.cpp(201,75): warning C4100: 'sizeInBytes': unreferenced formal parameter
1>D:\Hard Gainer\Source\PluginProcessor.cpp(201,65): warning C4100: 'data': unreferenced formal parameter
1>D:\Hard Gainer\Source\PluginProcessor.cpp(225,115): warning C4100: 'property': unreferenced formal parameter
1>D:\Hard Gainer\Source\PluginProcessor.cpp(225,68): warning C4100: 'treeWhosePropertyHasChanged': unreferenced formal parameter
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\memory(2064,35): error C2280: 'juce::AudioProcessorValueTreeState::SliderAttachment::SliderAttachment(const juce::AudioProcessorValueTreeState::SliderAttachment &)': attempting to reference a deleted function (compiling source file ..\..\Source\PluginEditor.cpp)
1>D:\JUCE\modules\juce_audio_processors\utilities\juce_AudioProcessorValueTreeState.h(452): message : see declaration of 'juce::AudioProcessorValueTreeState::SliderAttachment::SliderAttachment' (compiling source file ..\..\Source\PluginEditor.cpp)
1>D:\JUCE\modules\juce_audio_processors\utilities\juce_AudioProcessorValueTreeState.h(452,9): message : 'juce::AudioProcessorValueTreeState::SliderAttachment::SliderAttachment(const juce::AudioProcessorValueTreeState::SliderAttachment &)': function was explicitly deleted (compiling source file ..\..\Source\PluginEditor.cpp)
1>D:\Hard Gainer\Source\PluginEditor.cpp(44): message : see reference to function template instantiation 'std::unique_ptr<juce::AudioProcessorValueTreeState::SliderAttachment,std::default_delete<juce::AudioProcessorValueTreeState::SliderAttachment>> std::make_unique<juce::AudioProcessorValueTreeState::SliderAttachment,juce::AudioProcessorValueTreeState::SliderAttachment,0>(juce::AudioProcessorValueTreeState::SliderAttachment &&)' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\memory(2063,59): error C2248: 'juce::AudioProcessorValueTreeState::SliderAttachment::SliderAttachment': cannot access private member declared in class 'juce::AudioProcessorValueTreeState::SliderAttachment' (compiling source file ..\..\Source\PluginEditor.cpp)
1>D:\JUCE\modules\juce_audio_processors\utilities\juce_AudioProcessorValueTreeState.h(452): message : see declaration of 'juce::AudioProcessorValueTreeState::SliderAttachment::SliderAttachment' (compiling source file ..\..\Source\PluginEditor.cpp)
1>D:\JUCE\modules\juce_audio_processors\utilities\juce_AudioProcessorValueTreeState.h(441): message : see declaration of 'juce::AudioProcessorValueTreeState::SliderAttachment' (compiling source file ..\..\Source\PluginEditor.cpp)
1>Done building project "Hard Gainer_SharedCode.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========

I forgot to post the line in question in the previous reply. This is it now.

mGainValue =
        std::make_unique<AudioProcessorValueTreeState::SliderAttachment>
        (p.getAPVTS(), "gain", mGainSlider);

And mGainValue is std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment> ?

That’s right.

std::unique_ptr<AudioProcessorValueTreeState::SliderAttachment> mGainValue;