432 void RoleExternModel::getShareConfig(SourceList& sourceList, std::vector<UInt16>& packs, ShopModel& shopModel)
433 {
434 std::copy(Packs, Packs + SHARE_PRIZE, std::insert_iterator<std::vector<UInt16> >(packs, packs.begin()));
435 struct Fun {
436 std::vector<std::pair<UInt16, UInt8> > pairs;
437 void operator () (UInt16 type) {
438 pairs.push_back(std::make_pair<UInt16, UInt8>(type, Configuration::PACKS));
439 }
440 };
441 Fun fun();
442 std::for_each(Packs, Packs + SHARE_PRIZE, fun);
443 shopModel shopModel(fun.pairs);
444 shopModel.load(sourceList);
445 }
why the compiler said :
error: non-local function
‘Pet::RoleExternModel::getShareConfig(Pet::SourceList&,
std::vector >&,
Pet::ShopModel&)::Fun Pet::fun()’ uses local type
‘Pet::RoleExternModel::getShareConfig(Pet::SourceList&,
std::vector >&,
Pet::ShopModel&)::Fun’
how to make it legel?
This line is the problem:
It declares a function names
funthat takes no arguments and returns aFunobject.This is called the most vexing parse.
Remove the parentheses and you declare an object named
funinstead.