Edit: I think I understand the problem now based on additional comments/edits. My next suggestion is to try a template:
template<typename GlmType>
class ValuePtr {
private:
const GlmType& m_glm;
public:
ValuePtr(const GlmType& glm)
:m_glm(glm)
{
}
operator const void*() {
return glm::value_ptr(m_glm);
}
};
class Mat4x4: public glm::mat4x4, public ValuePtr<Mat4x4> {
public:
Mat4x4()
: ValuePtr(*this)
{
}
};
etc. If you need everyone to have a common base class, you'd just need another layer above the templated one.
Original:
I'm not entirely sure what you need to do, so I'll try to cover all the bases. One possibility is that the base class ValuePtr doesn't need operator const void*()
at all. In that case, just move it to Mat4x4:
class ValuePtr {
};
class Mat4x4: public glm::mat4x4, public ValuePtr {
operator const void*() {
return glm::value_ptr(*this);
}
};
But maybe you want to have the function in both classes, and do something different in each case. I don't know what you'd want the base version to do, so let's just have it return null:
class ValuePtr {
operator const void*() {
return nullptr;
}
};
class Mat4x4: public glm::mat4x4, public ValuePtr {
operator const void*() {
return glm::value_ptr(*this);
}
};
Finally, maybe you'll be deriving multiple classes from ValuePtr, and all of them need to be castable to const void*, but there's no reasonable way to implement that in the base itself. In that case, use a pure virtual function:
class ValuePtr {
virtual operator const void*() = 0;
};
class Mat4x4: public glm::mat4x4, public ValuePtr {
virtual operator const void*() override {
return glm::value_ptr(*this);
}
};
(the override
keyword is optional, and actually may not work depending on what compiler you have).