Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8690427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:53:59+00:00 2026-06-12T23:53:59+00:00

I have a class hierarchy like this one (this is the actual class but

  • 0

I have a class hierarchy like this one (this is the actual class but I cleaned it up):

class Notifiable 
{
public:
   void notify();
}

template <class Exp>
class Batch : public Notifiable
{
public:
    void run();
}

void Batch<Exp>::run()
{
   done.clear();
   generator->resetGeneration();

   while(generator->hasMoreParameters())
   {
       // Lock for accessing active
       std::unique_lock<std::mutex> lock(q_mutex, std::adopt_lock);

       // If we've less experiments than threads
       if (active.size() < threads)
       {
          Configuration conf = generator->generateParameters();
        Exp e(executable, conf);
           //std::weak_ptr<Batch<Exp>> bp;
           //bp.reset(this);

           std::thread t(&Exp::run, e, *this);
           std::thread::id id = t.get_id();
           active.insert(id);
           t.detach();
       }
       q_control.wait(lock, [this] { return active.size() < threads; } );
   }
}


class Experiment
{
public:
   void run(Notifiable& caller)
   {
      do_stuff();
      caller.notify();
   }

   virtual void do_stuff() = 0;
}

class MyExperiment : public Experiment 
{
public:
   void do_stuff() 
   {
       // do my stuff
   }
}

I then instantiate a Batch<MyExperiment> object and call run(), using this code:

Batch<ELExperiment> b(pex, options["name"].as<string>(), options["executable"].as<string>());
    b.run();

but I get this at compile-time:

In file included from /opt/local/include/gcc47/c++/bits/move.h:57:0,
                 from /opt/local/include/gcc47/c++/bits/stl_pair.h:61,
                 from /opt/local/include/gcc47/c++/bits/stl_algobase.h:65,
                 from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
                 from /opt/local/include/gcc47/c++/ios:41,
                 from /opt/local/include/gcc47/c++/ostream:40,
                 from /opt/local/include/gcc47/c++/iostream:40,
                 from json2cli/main.cpp:9:
/opt/local/include/gcc47/c++/type_traits: In instantiation of 'struct std::_Result_of_impl<false, false, std::_Mem_fn<void (Experiment::*)(Notifiable&)>, MyExperiment, Batch<MyExperiment> >':
/opt/local/include/gcc47/c++/type_traits:1857:12:   required from 'class std::result_of<std::_Mem_fn<void (Experiment::*)(Notifiable&)>(MyExperiment, Batch<MyExperiment>)>'
/opt/local/include/gcc47/c++/functional:1563:61:   required from 'struct std::_Bind_simple<std::_Mem_fn<void (Experiment::*)(Notifiable&)>(MyExperiment, Batch<MyExperiment>)>'
/opt/local/include/gcc47/c++/thread:133:9:   required from 'std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (Experiment::*)(Notifiable&); _Args = {MyExperiment&, Batch<MyExperiment>&}]'
json2cli/batch.hh:86:46:   required from 'void Batch<Exp>::run() [with Exp = MyExperiment]'
json2cli/main.cpp:113:15:   required from here
/opt/local/include/gcc47/c++/type_traits:1834:9: error: no match for call to '(std::_Mem_fn<void (Experiment::*)(Notifiable&)>) (MyExperiment, Batch<MyExperiment>)'
In file included from /opt/local/include/gcc47/c++/memory:81:0,
                 from json2cli/parameterexpression.hh:19,
                 from json2cli/main.cpp:13:
/opt/local/include/gcc47/c++/functional:525:11: note: candidates are:
/opt/local/include/gcc47/c++/functional:548:7: note: _Res std::_Mem_fn<_Res (_Class::*)(_ArgTypes ...)>::operator()(_Class&, _ArgTypes ...) const [with _Res = void; _Class = Experiment; _ArgTypes = {Notifiable&}]
/opt/local/include/gcc47/c++/functional:548:7: note:   no known conversion for argument 1 from 'MyExperiment' to 'Experiment&'
/opt/local/include/gcc47/c++/functional:553:7: note: _Res std::_Mem_fn<_Res (_Class::*)(_ArgTypes ...)>::operator()(_Class*, _ArgTypes ...) const [with _Res = void; _Class = Experiment; _ArgTypes = {Notifiable&}]
/opt/local/include/gcc47/c++/functional:553:7: note:   no known conversion for argument 1 from 'MyExperiment' to 'Experiment*'
/opt/local/include/gcc47/c++/functional:559:2: note: template<class _Tp> _Res std::_Mem_fn<_Res (_Class::*)(_ArgTypes ...)>::operator()(_Tp&, _ArgTypes ...) const [with _Tp = _Tp; _Res = void; _Class = Experiment; _ArgTypes = {Notifiable&}]
/opt/local/include/gcc47/c++/functional:559:2: note:   template argument deduction/substitution failed:
In file included from /opt/local/include/gcc47/c++/bits/move.h:57:0,
                 from /opt/local/include/gcc47/c++/bits/stl_pair.h:61,
                 from /opt/local/include/gcc47/c++/bits/stl_algobase.h:65,
                 from /opt/local/include/gcc47/c++/bits/char_traits.h:41,
                 from /opt/local/include/gcc47/c++/ios:41,
                 from /opt/local/include/gcc47/c++/ostream:40,
                 from /opt/local/include/gcc47/c++/iostream:40,
                 from json2cli/main.cpp:9:
/opt/local/include/gcc47/c++/type_traits:1834:9: note:   cannot convert 'std::declval<Batch<MyExperiment> >()' (type 'Batch<MyExperiment>') to type 'Notifiable&'

It looks like I can’t just expect to generalize any Batch<Exp> into a Notifiable for function calling. Can you confirm that?

Update sorry, I thought I could avoid dumping all of my code inside the question, but in fact there must be something wrong in the way I spawn the thread for Batch<Exp>::run(). There are still a couple of details missing, but I don’t really think they are related (e.g. how I generate the parameters for the experiment).

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:54:00+00:00Added an answer on June 12, 2026 at 11:54 pm

    Your error is not in the code that you show to us, Some where in the code you try to bind your run and create a thread using std::thread and that’s the problem, since it can’t create a correct struct for your bound function and simplest workaround is to write your own wrapper:

    template< class Expr >
    struct my_bind {
        my_bind( Expr& e, Notifiable& n ) : e_( e ), n_(n) {}
        void operator()() {e_.run(n_);}
        Expr& e_;
        Notifiable& n_;
    };
    

    And then use your own wrapper to start the function, I can’t say for sure but I think this is a bug in compiler (all compilers have this bug: GCC, MSVC, …) that when you expression get complicated they fail to use it in std::bind!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object hierarchy that looks something like this: public class Book {
I have a class hierarchy similar to this one: public static class BaseConfiguration {
Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)
We have a class hierarchy similar to this one: public class TestDereference { private
Suppose I have class hierarchy like the one shown in picture. Suppose I need
I have one class which contains two more classes like hierarchy. When I'm displaying
I have case where the class hierarchy is something like this, +---------------+ | UIElement
I have a class hierarchy like this: ClassA inherits from NSObject ClassB inherits from
I have a small class hierarchy where I would like to have a child
I have a quite complex class hierarchy in which the classes are cross-like depending

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.