I am trying to create an std::set with a function I defined for sorting,
but I get the error: “Error: function “GFX::MeshCompare” is not a type name”
Mesh.h
namespace GFX
{
struct Mesh
{
[...]
};
inline bool MeshCompare(const Mesh& a, const Mesh& b)
{
return ( (a.pTech < b.pTech) ||
( (b.pTech == a.pTech) && (a.pMaterial < b.pMaterial) ) ||
( (b.pTech == a.pTech) && (a.pMaterial == b.pMaterial) && (a.topology < b.topology) )
);
}
};
Renderer.h
namespace GFX
{
class Renderer
{
private:
[...]
std::set<Mesh, MeshCompare> m_Meshes;
};
};
What am I doing wrong and how do I fix it?
The second template argument to
std::sethas to be a type, not value .If you want to use function (which is value, not type), then you’ve to pass it as argument to the constructor, which means you can do this:
Or, define a functor class, and pass this as second type argument to
std::set.And then use it: