I’m currently writing a 2D vector class which contains a function to round x and y of the vector to the nearest int. to do this I thought I could use the <math.h> round() but the name of my Vector2 function is Vector2.round(), this causes an error because the computer thinks I’m giving too many arguments (1) because my Vector2.round() function isn’t meant to take any arguments, I though putting math::round() instead of round() might work but I guess the math library doesn’t use a namespace because it didn’t work, how can I tell the computer that I’m trying to access the <math.h> method as opposed to the one I wrote.
>Solution :
There Are Two Approaches:
- Using
::round()instead ofmath::round(). This Approach is however compiler dependent and as cited here works well only for Microsoft Or GNU Compiler. - Using
cmathlibrary. Supports the same functions asmath.hbut its functions are present instdnamespace allowing you to usestd::round()as cited here