How to create multithread logger in c++

  c++, multithreading, visual-studio

I want to create a multithread logger in c++ which can be called from c code as well.

This is in my source.cpp file:

#include <cstdlib>
#include <iostream>
#include <thread>
#include "source.h"
using namespace std;

#ifdef __cplusplus
extern "C" {
#endif
class thread_obj {
public:
    void operator()(float* x)
    {
        printf("value: %d", x);
    }
};

void log(float value)
{
    thread th1(thread_obj(), value);
    th1.join();
}

#ifdef __cplusplus
}
#endif

And this is in source.h:

#ifdef __cplusplus
extern "C" {
#endif
    void log(float value);
#ifdef __cplusplus
}
#endif

And now I want to use this from a C file like: log(myFloatValue);, of course with included header file.

But I got some strange errors, like:

Error   C2672   'invoke': no matching overloaded function found myproj C:Program Files (x86)Microsoft Visual Studio19CommunityVCToolsMSVC.27.29110includethread   43  
Error   C2893   Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 &&...) noexcept(<expr>)'  myproj C:Program Files (x86)Microsoft Visual Studio19CommunityVCToolsMSVC.27.29110includethread   39  
Error   C2780   'unknown-type std::invoke(_Callable &&) noexcept(<expr>)': expects 1 arguments - 2 provided hackatlon_0_0_1 C:Program Files (x86)Microsoft Visual Studio19CommunityVCToolsMSVC.27.29110includethread  39  

My question is, how can I do this, or how can I solve these errors?

Source: Windows Questions C++

LEAVE A COMMENT