2

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?

Jurze
  • 209
  • 2
  • 11
  • 4
    Please **[edit]** your question with an [mcve] or [SSCCE (Short, Self Contained, Correct Example)](http://sscce.org) – NathanOliver Oct 02 '17 at 17:55
  • "attempt to use a deleted function" is usually a clash between something attempting to use the copy constructor of a class that has been declared with the JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR macro which works by deleting the copy constructor. – Dave E Oct 09 '17 at 14:50
  • Upvoted your question. Not sure why it had no votes, but it lead me here which helped me. – Sonny Parlin Jan 24 '22 at 15:04

1 Answers1

5

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);
Jurze
  • 209
  • 2
  • 11
  • upvoted your question AND answer: kudos for taking time to answer your own question to help the rest of us – Rhubarb Mar 31 '21 at 20:58