Search code examples
c++multithreadingjuce

C++ Threading : Attempt to use a deleted function


Im making a MIDI generator in C++ using JUCE framework. I'd like to do the generating in a different thread so it won't block my entire program. This is how I make my thread:

    std::thread generationThread (&MainContentComponent::generateProgression,var1, var2);

generateProgression is the function that generate's MIDI based on var1 (integer) and var2 (boolean)

The thread is created in the MainContentComponent class, and generateProgression is a function of that class.

The problem is that I'm getting a compile error saying : "Attempt to use a deleted function". Could anyone tell me what I'm doing wrong?


Solution

  • Not sure why I got so many downvotes on this one. Luckily a friend of mine told me what was wrong. I needed to also give the current context. As the thread is created in the class that also contains the function the context can just be "this".

        std::thread(&Fooclass::fooMainloopMemberFunction, context, argument);
    

    or in my case

        std::thread generationThread (&MainContentComponent::generateProgression,this,var1, var2);