1>c:\program files\microsoft visual studio 10.0\vc\include\map(229): warning C4180:
qualifier applied to function type has no meaning; ignored
1> d:\...\gmproject.h(122)
: see reference to class template instantiation 'std::map<_Kty,_Ty>'
being compiled
1> with
1> [
1> _Kty=GMProject::DuplicateTy,
1> _Ty=GMProject::DuplicateFn
1> ]
Well my class has these typedefs (pTree is a container):
typedef void *DuplicateFn(pTree&, const pTree&);
enum DuplicateTy {
SKIP,
OVERWRITE,
ASK
};
typedef std::map<DuplicateTy, DuplicateFn> DuplicateMapTy;
And lines 122,123 are:
static const DuplicateMapTy DuplicateFns;
static DuplicateMapTy DuplicateFns_INIT();
How do I indicate this map can’t change – and makes it static to the class?
My goal is to create a map so I can “get” a function pointer from the enumerate. (The client code will provide the enum, then the class itself resolves the enum to a function).
The issue has nothing to do with the map being const: it’s a warning because the returntype of the const version of
std::map::at()isconst mapped_type&. This code produces the warning just as well:The retrun type of map’s
athere isWhile this warning has it’s place (although I’m not too sure in this particular situation it is justified by the standard), in this case there should be no harm to disable it locally for the code using the map, or if you do not like the pragma hassle, wrap your function pointer into a simple struct.
edit as Gorpik points out in the comment below, this is actually generated at that specific location though the function isn’t used. Seems indeed the VS compiler is kind of aggressive when hunting for warnings: it does consider declarations.