Active Member Mind Rapist 188 Posted December 12, 2018 Active Member Share Posted December 12, 2018 I have this error: In file included from ./any_function.h:29: ./any_function.inc:98:3: error: no matching function for call to object of type '(lambda at guild.cpp:1023:39)' held(func_arg); ^~~~ I am trying to pass this: DBManager::instance().FuncAfterQuery([this](auto&& data) { return this->RefreshCommentForce(data); }, (char*)ch->GetPlayerID(), Other methods have failed too (std::bind). I am compiling with C++17. Does anyone know what's wrong? Link to comment Share on other sites More sharing options...
ridetpro 116 Posted December 12, 2018 Share Posted December 12, 2018 Acum 48 minute, Mind Rapist a spus: I have this error: In file included from ./any_function.h:29: ./any_function.inc:98:3: error: no matching function for call to object of type '(lambda at guild.cpp:1023:39)' held(func_arg); ^~~~ I am trying to pass this: DBManager::instance().FuncAfterQuery([this](auto&& data) { return this->RefreshCommentForce(data); }, (char*)ch->GetPlayerID(), Other methods have failed too (std::bind). I am compiling with C++17. Does anyone know what's wrong? void CGuild::AddComment(LPCHARACTER ch, const std::string &str) { int player_id = ch->GetPlayerID(); if (str.length() > GUILD_COMMENT_MAX_LEN) { return; } char text[GUILD_COMMENT_MAX_LEN * 2 + 1]; DBManager::Instance().EscapeString(text, sizeof(text), str.c_str(), str.length()); DBManager::Instance().FuncAfterQuery( [this, player_id] {this->RefreshCommentForce(player_id); }, "INSERT INTO guild_comment(guild_id, name, notice, content, time) VALUES(%u, '%s', %d, '%s', NOW())", m_data.guild_id, ch->GetName(), (str[0] == '!') ? 1 : 0, text); } Use std::function instead of any_function 1 Link to comment Share on other sites More sharing options...
Active Member Mind Rapist 188 Posted December 12, 2018 Author Active Member Share Posted December 12, 2018 20 minutes ago, ridetpro said: void CGuild::AddComment(LPCHARACTER ch, const std::string &str) { int player_id = ch->GetPlayerID(); if (str.length() > GUILD_COMMENT_MAX_LEN) { return; } char text[GUILD_COMMENT_MAX_LEN * 2 + 1]; DBManager::Instance().EscapeString(text, sizeof(text), str.c_str(), str.length()); DBManager::Instance().FuncAfterQuery( [this, player_id] {this->RefreshCommentForce(player_id); }, "INSERT INTO guild_comment(guild_id, name, notice, content, time) VALUES(%u, '%s', %d, '%s', NOW())", m_data.guild_id, ch->GetName(), (str[0] == '!') ? 1 : 0, text); } You are a life saver! The compile is way ahead now. I even needed this code on my next error: for_each(v.begin(), v.end(), [this](auto&& data) { return this->UpdateStateMachine(iPulse); }); Here is a little different tho, here the UpdateStateMachine is a member of CHARACTER while this function is a member of CHARACTER_MANAGER (exact location: char_manager.cpp -> void CHARACTER_MANAGER::Update(int iPulse)). I tried replacing [this] with [CHARACTER] and [&CHARATCTER] but got this error: char_manager.cpp:693:8: error: 'CHARACTER' in capture list does not name a variable [&CHARACTER](auto&& data) { retu... ^ Link to comment Share on other sites More sharing options...
ridetpro 116 Posted December 13, 2018 Share Posted December 13, 2018 std::for_each(v.begin(), v.end(), std::bind(&CHARACTER::UpdateStateMachine, std::placeholders::_1, iPulse)); Link to comment Share on other sites More sharing options...
Active Member Mind Rapist 188 Posted December 13, 2018 Author Active Member Share Posted December 13, 2018 It worked! I can't believe I didn't think about that. It's over half now, hitting at char_battle.cpp. It had a problem with random_shuffle (removed at 17) so I made some research and changed it to std::shuffle and included algorithm and random. I passed a third parameter and it looks like this now: std::shuffle(vec_bSlots.begin(), vec_bSlots.end(), std::default_random_engine(send)); but it seems to have a problem with that third parameter: /usr/include/c++/v1/random:1959:8: error: member reference base type 'int (int, const void *, unsigned int, int)' is not a structure or union __q.generate(__ar, __ar + __k + 3); ~~~^~~~~~~~~ ... char_battle.cpp:1074:55: note: in instantiation of function template specialization 'std::__1::linear_congruential_engine<unsigned int, 48271, 0, 2147483647>::linear_congruential_engine<int (int, const void *, unsigned int, int)>' requested here ...std::shuffle(vec_bSlots.begin(), vec_bSlots.end(), std::default_random_e... ^ EDIT: Easily fixed! For future reference: // Instead of std::shuffle(vec_bSlots.begin(), vec_bSlots.end(), std::default_random_engine(send)); // Type this std::random_device rd; std::mt19937 g(rd()); std::shuffle(vec_bSlots.begin(), vec_bSlots.end(), g); Link to comment Share on other sites More sharing options...
Active Member Mind Rapist 188 Posted December 13, 2018 Author Active Member Share Posted December 13, 2018 Ok seems like I've hit a dead end!!! I thought by upgrading and compiling to C++17 would solve this but now that everything is perfect, here it is again. I have no idea what it means or how to fix it but in any case someone wants to help here is the object error: Linking...../game_r70140-BETA_release release/guild.o: In function `CGuild::GuildPointChange(unsigned char, int, bool)': guild.cpp:(.text+0x3939): undefined reference to `CGuild::CGuild(CGuild const&)' guild.cpp:(.text+0x39d6): undefined reference to `CGuild::CGuild(CGuild const&)' release/guild.o: In function `CGuild::SkillLevelUp(unsigned int)': guild.cpp:(.text+0x48fb): undefined reference to `CGuild::CGuild(CGuild const&)' guild.cpp:(.text+0x49be): undefined reference to `CGuild::CGuild(CGuild const&)' release/cipher.o: In function `DH2KeyAgreement::Prepare(void*, unsigned int*)': cipher.cpp:(.text+0xbe2): undefined reference to `CryptoPP::AlignedDeallocate(void*)' cipher.cpp:(.text+0xc9a): undefined reference to `CryptoPP::AlignedDeallocate(void*)' cipher.cpp:(.text+0xcd3): undefined reference to `CryptoPP::AlignedDeallocate(void*)' cipher.cpp:(.text+0xd0c): undefined reference to `CryptoPP::AlignedDeallocate(void*)' cipher.cpp:(.text+0xea7): undefined reference to `CryptoPP::AlignedDeallocate(void*)' release/cipher.o:cipher.cpp:(.text+0xf76): more undefined references to `CryptoPP::AlignedDeallocate(void*)' follow release/cipher.o: In function `CryptoPP::MontgomeryRepresentation::MontgomeryRepresentation(CryptoPP::MontgomeryRepresentation const&)': cipher.cpp:(.text._ZN8CryptoPP24MontgomeryRepresentationC2ERKS0_[_ZN8CryptoPP24MontgomeryRepresentationC2ERKS0_]+0x4e): undefined reference to `CryptoPP::AlignedAllocate(unsigned int)' cipher.cpp:(.text._ZN8CryptoPP24MontgomeryRepresentationC2ERKS0_[_ZN8CryptoPP24MontgomeryRepresentationC2ERKS0_]+0xc3): undefined reference to `CryptoPP::AlignedDeallocate(void*)' release/cipher.o: In function `CryptoPP::ModularArithmetic::ModularArithmetic(CryptoPP::ModularArithmetic const&)': cipher.cpp:(.text._ZN8CryptoPP17ModularArithmeticC2ERKS0_[_ZN8CryptoPP17ModularArithmeticC2ERKS0_]+0x83): undefined reference to `CryptoPP::AlignedDeallocate(void*)' cipher.cpp:(.text._ZN8CryptoPP17ModularArithmeticC2ERKS0_[_ZN8CryptoPP17ModularArithmeticC2ERKS0_]+0xc3): undefined reference to `CryptoPP::AlignedDeallocate(void*)' release/cipher.o: In function `CryptoPP::ModularArithmetic::~ModularArithmetic()': cipher.cpp:(.text._ZN8CryptoPP17ModularArithmeticD2Ev[_ZN8CryptoPP17ModularArithmeticD2Ev]+0x32): undefined reference to `CryptoPP::AlignedDeallocate(void*)' cipher.cpp:(.text._ZN8CryptoPP17ModularArithmeticD2Ev[_ZN8CryptoPP17ModularArithmeticD2Ev]+0x67): undefined reference to `CryptoPP::AlignedDeallocate(void*)' release/cipher.o:cipher.cpp:(.text._ZN8CryptoPP17ModularArithmeticD2Ev[_ZN8CryptoPP17ModularArithmeticD2Ev]+0x9c): more undefined references to `CryptoPP::AlignedDeallocate(void*)' follow clang-8: error: linker command failed with exit code 1 (use -v to see invocation) gmake: *** [Makefile:90: ../game_r70140-BETA_release] Error 1 Link to comment Share on other sites More sharing options...
Active Member Mind Rapist 188 Posted December 13, 2018 Author Active Member Share Posted December 13, 2018 Well he is the only one gave me answers and his code works like a charm so imma take my chances 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now