ErNabbone 5 Posted June 23, 2016 Share Posted June 23, 2016 Hello guys! To start I'd like to apologize for my bad english; sooner or later I'll improve it I'm not new to C++ but I never played much with metin2 server sources. Yesterday I was developing a little script in game/party.cpp, in the end of the function "void CParty::P2PJoin(DWORD)", where I need to store all party's Players ID. I get an error on a CParty method: "no matching function for call to 'CParty::ForEachOnlineMember(CParty::P2PJoin(DWORD)::FPartyPIDCollector&, long int)'"; It's like I wouldn't initialized that function but I already included the header "party.h", where that (public) method is declared in the CParty class as "template <class Func> void ForEachOnlineMember(Func & f);" and where it is also defined as follow: template <class Func> void CParty::ForEachOnlineMember(Func & f) { TMemberMap::iterator it; for (it = m_memberMap.begin(); it != m_memberMap.end(); ++it) if (it->second.pCharacter) f(it->second.pCharacter); } The critical section of my code is... [...] LPCHARACTER leader = CHARACTER_MANAGER::instance().FindByPID(pid); if (leader && leader->GetDesc()) { LPPARTY pParty = leader->GetParty(); if (pParty) { struct FPartyPIDCollector // <- thanks to "Dash" @metin2dev.org for this struct { std::vector <DWORD> vecPIDs; FPartyPIDCollector() {} void operator () (LPCHARACTER ch) { vecPIDs.push_back(ch->GetPlayerID()); } }; FPartyPIDCollector f; pParty->ForEachOnlineMember(f); [...] } [...] } I'm almost sure that it's just a noobs thing, but I really can't understand what's the reason of this error u.u Maybe are there differences between CParty and LPPARTY? Best regards, Erich Link to comment Share on other sites More sharing options...
.Devil. 28 Posted June 23, 2016 Share Posted June 23, 2016 Write the FPartyPIDCollector struct out of the function. You can't write nested functions like this. 1 Link to comment Share on other sites More sharing options...
ErNabbone 5 Posted June 24, 2016 Author Share Posted June 24, 2016 Wow @.Devil., you're right! That's the error! Thank you! But I always wrote nested functions, why does not this works? (just for my knowledge, it works fine declaring the struct in the global scope) [Post scriptum: anyway thanks to @arves100 for his help too!] Link to comment Share on other sites More sharing options...
.Devil. 28 Posted June 24, 2016 Share Posted June 24, 2016 Because not all compiler works with them nested. You can't, anyway, make a function inside another function (I've write this in the previous post but I was referring to local classes/structs).. For example with C++98 you can call/declare struct/classes only from the function where they are declared (but not as argument for another function, like you did). 1 Link to comment Share on other sites More sharing options...
ErNabbone 5 Posted June 24, 2016 Author Share Posted June 24, 2016 Ah, easier than I thought... I have read that from gcc11+ it was always allowed; apparently it was wrong. Thank you again, regards! 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