BaseSort member variable?

  • On 14/07/2016 at 12:06, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   17 
    Platform:   Windows  ;   Mac OSX  ; 
    Language(s) :     C++  ;


    I'm looking for a way to implement a variable sorting crtiteria in my BaseSort class, but I'm not getting it to work. I just want to sort an array with vectors using a tolerance value (eps) :

    class SortVector : public maxon::BaseSort <SortVector>   
         static Bool LessThan(Vector a, Vector b)   
              if (a.z < b.z - eps) return true;   
              if (a.z > b.z + eps) return false;   
              return (a.x < b.x);   
         SortVector(Float d)   
              eps = d;   
         static Float eps;   
    maxon::BaseArray<Vector> points;   
    //... filling the array ...   
    SortVector sort(10);   

    I want to start the sorting using the tolerance value, but the compiler gives me an unsolved symbol "eps" error because of the static declaration. But I can't omit static, because LessThan wouldn't know "eps". And finally I can't omit static for LessThan().

    It happens frequently, that I need additional variable parameters for sorting. How is the provided way to do this?

    Thanks of any help.

  • On 14/07/2016 at 17:08, xxxxxxxx wrote:

    Did you forget to add the definition of SortVector::eps also in your actual code? Something like this in a
    translation unit (.cpp file).

    Float SortVector::eps = 1.0e-7;  // just an example value

  • On 15/07/2016 at 01:45, xxxxxxxx wrote:

    You only have the declaration of the static member but you also need to give it a definition (i.e. what Niklas provided) to actually make it exist.

  • On 15/07/2016 at 03:21, xxxxxxxx wrote:

    Thanks. Have to read a chapter about static stuff I guess.

Log in to reply