c++ - How to define methods in a base class that only work in derived classes? -
The title is slightly ambiguous, so I will say an example of what I want to achieve:
Class ValuePtr {Public: Operator Canned void * () {return glm :: value_ptr (* this); // value ptr will not work on this class // (works only on glm type)}}; Square mat4x4: public glm :: mat4x4, public valuePtr {// ... but will work here}; Square Vec3: Public glm :: vec3, Public ValuePtr {// ... and here. } Is such a thing possible?
glm :: value_ptr works only on glm type like glm :: mat4x4 , glm: : Vec3 , etc. The above seen method works if I implement it directly into derivative classes, but they should all be defined as operator construct * zero * in the same way. I should behave like a special behavior: define it in the general base class, whereas definition only works in derived classes.
Thank you for the answer, I use this solution: template & lt; Class T & gt; Class ValuePtr: Public T {Public: Operator Constant * () {return glm :: value_ptr (* this); }}; Class Mat4x4: Public Value PTR & lt; Glm :: mat4x4 & gt; {}; Edit: I think I now have additional comment / editing problem based on I understand. My next suggestion is to try the template:
template & lt; Typename GlmType & gt; Class ValuePtr {Personal: Const Glams Type & amp; M_glm; Public: Valu Prati (Cons Glattype and Glam): M_GLM (Glam) {} Operator Cant Voed * () {return glm :: value_ptr (m_glm); }}; Class Mat4x4: public glm :: mat4x4, public value pricing & lt; Mat4x4 & gt; {Public: Mat4x4 (): ValuePtr (* this) {}}; etc. If you need everyone for a normal base class, then you need another layer above the thermoplated one.
Origin:
I am not sure what you have to do, then I will try to cover all the bases One possibility is that the base class values the value of operator Construct zero * () is not required, just move it to Mat4x4: class ValuePtr {}; Square mat4x4: public glm :: mat4x4, public value per operator {operator const void * () {return glm :: value_ptr (* this); }}; But you may want to celebrate both classes and want to do something different in each case. I do not know what you want to do the base version, so let's just clear it:
class ValuePtr {operator const void * () {return nullptr; }}; Square mat4x4: public glm :: mat4x4, public value per operator {operator const void * () {return glm :: value_ptr (* this); }}; Finally, you may obtain many sections from ValuePtr, and it must be justified to make them mandatory, but there is no proper way to apply the base. In that case, use a pure virtual function: class ValuePtr {virtual operator font blank * () = 0; }; Class Mat4x4: Public glm :: mat4x4, Public ValuePtr {Virtual Operator Cont (*) override without exception {return glm :: value_ptr (* this); }}; ( override keyword is optional, and can not actually work on the basis of the compiler).
Comments
Post a Comment