Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using only certain functions from a library?

i would like to use only certain functions from math.h (WITHOUT including the entire library)

for example, i need to use "sqrt" and "exp", but i have variables named "y1" (and possibly others) which conflict with definitions in math.h

how can i use only certain functions from a library like that?

i tried

#define sqrt cmath::sqrt

but that did not work, i have seen something like that before with

#define cout std::cout

i think, so i thought it might work.

any ideas?

like image 434
drjrm3 Avatar asked Sep 03 '25 14:09

drjrm3


1 Answers

Put your code in your own namespace. By using namespace operator (::) you can distinguish variables with the same name (and which are in the same scope).

like image 199
Bojan Komazec Avatar answered Sep 05 '25 03:09

Bojan Komazec