Namespaces not allowed in Vex V5 text?

Hi, I have a struct inside of a namespace and when I try to use the struct in any capacity, it says both the namespace and the struct don’t exist. However if I put the struct outside of the namespace it works fine. I’m currently using an outside library (it is only raw c++ 17 so I thought it would work fine on Vex). Is there any explanation for this? If I can’t use namespaces that’s a very strange, specific thing to ban. Thank you.

1 Like

Namespaces work perfectly fine for me, you are likely doing something incorrectly. Could you please share your code?

1 Like
namespace MathThings {

using RndGenerator = std::mt19937_64; //Mersenne Twister Algorithm, defining this makes it act like srand(time(0) and using it like RndEngine() is rand()


struct MathConstants {

          static constexpr float Delta = 0.2f;
          ...

};


} 

Neither MathThings nor MathThings::MathConstants exists.

The code you sent builds for me without any issues.

// ---- START VEXCODE CONFIGURED DEVICES ----
// ---- END VEXCODE CONFIGURED DEVICES ----

#include "vex.h"

using namespace vex;

namespace MathThings {
  //using RndGenerator = std::mt19937_64; //Mersenne Twister Algorithm, defining this makes it act like srand(time(0) and using it like RndEngine() is rand()

  struct MathConstants {

    static constexpr float Delta = 0.2f;

  };
} 

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  MathThings::MathConstants x;
}

What is the error message that you are getting?

1 Like

Never mind, apparently even though I looked directly at the header file name letter for letter and typed it, I still made a typo. -_- I am going to be using std::clamp though, and it’s only c++ 17 onwards, so how can I make the IDE go to c++17?

I am not aware of any method to upgrade to c++ 17. However, you can create your own clamp method using something like this:

template <typename T>
T clamp(const T& n, const T& lower, const T& upper) {
  return std::max(lower, std::min(n, upper));
}

From this stack overflow post

Edit:
According to this post by jpearman, it should be possible to use c++ 17, but it seems like its untested and will likely cause you more trouble than its worth. I would recommend just making your own implementations for the methods that you need to use.

3 Likes