I am making something in c++, it doesn't have any errors visible in Visual Studio code, but when I use g++ to be able to execute it, I get this error:
In file included from Main.cpp:6: In file included from ./Filechange/Filechange.hpp:1: ./Filechange/Filechange.cpp:14:24: error: expected expression std::thread first ([&wtime,&f,&fn]() mutable { ^ Main.cpp:16:33: error: expected expression OnFilechange("FileEvent", 0.5, [](char* txt){ ^ 2 errors generated. These are the files: Main.cpp:
#include <lua.hpp> #include <iostream> #include <chrono> #include <thread> #include <stdio.h> #include "Filechange/Filechange.hpp" void wait(int seconds) { std::this_thread::sleep_for(std::chrono::seconds(seconds)); } int main(int argc, char const *argv[]) { lua_State *State = luaL_newstate(); OnFilechange("FileEvent", 0.5, [](char* txt){ std::cout << txt << std::endl; }); lua_close(State); return 0; } Filechange.cpp:
#include <thread> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <string> #include <fstream> char* StringToChar(std::string str){ char* Array = new char[str.length() + 1]; strcpy(Array,str.c_str()); return Array; } void OnFilechange(const char *f, float wtime, void (*fn)(char* txt)){ std::thread first ([&wtime,&f,&fn]() mutable { std::ifstream file(f); std::string str; std::string filecontents; while (std::getline(file,str)){ filecontents += str; filecontents.push_back('\n'); } char* LastContents = StringToChar(filecontents); char* CurrentContents = StringToChar(filecontents); while (true){ if (wtime != 0){ std::this_thread::sleep_for(std::chrono::milliseconds(int(wtime*1000))); } filecontents = ""; while (std::getline(file,str)){ filecontents += str; filecontents.push_back('\n'); } CurrentContents = StringToChar(filecontents); if (strcmp(LastContents, CurrentContents) != 0){ LastContents = StringToChar(filecontents); fn(StringToChar(filecontents)); } } }); } Filechange.hpp:
#include "Filechange.cpp" #ifndef FILECHANGE_HPP #define FILECHANGE_HPP #include <thread> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <string> #include <fstream> void OnFilechange(const char *f,float wtime,void (*fn)(char txt)); #endif There's also a extension less file named FileEvent which will change in the runtime using other code files. The Filechange.cpp and Filechange.hpp are in a folder named "Filechange"
OnFilechangehere? Is the entire body of the function supposed to be a lambda that's the argument tofirst?.hppfile include your.cppfile?