Namespace for VEX header file

   1013   0   2
User Avatar
Member
5 posts
Joined: Aug. 2022
Offline
I am trying to organize a growing vex header library. The biggest concern are duplicate functions/macros. My initial idea using namespaces did not play out as expected as I didnt find any documentation and my c inspired experiments did not lead anywhere.
The second idea putting everything into a struct like:

struct NAMESPACE_myMath {
    float add(float a, b) { return a + b; }
    float sub(float a, b) { return this->add(a, -b); }
}
#define myMath NAMESPACE_myMath()

While this technically works, I find it ugly for several reasons, first, I dont know the performance/memory footprint (could be just fine, or not?) and second, referring to other functions using this->doesnt sit right with me.

The third idea would be to just prefix every function:
float myMath__add(float a, b) { return a + b; }
float myMath__sub(float a, b) { return myMath__add(a, -b); }
Its also a little ugly and makes everything longer...

Is there something I missed? A suggested workflow? Another workaround?

Thanks in advance!

Edit: formatting
Edited by dominikh - Aug. 18, 2022 11:13:39
  • Quick Links