Я разрабатываю проект, который работает с несколькими арифметическими типами. Поэтому я создал заголовок, где определены минимальные требования для определяемого пользователем арифметического типа:
user_defined_arithmetic.h:
typedef double ArithmeticF; // The user chooses what type he
// wants to use to represent a real number
namespace arithmetic // and defines the functions related to that type
{
const ArithmeticF sin(const ArithmeticF& x);
const ArithmeticF cos(const ArithmeticF& x);
const ArithmeticF tan(const ArithmeticF& x);
...
}
Меня беспокоит то, что когда я использую такой код:
#include "user_defined_arithmetic.h"
void some_function()
{
using namespace arithmetic;
ArithmeticF lala(3);
sin(lala);
}
Я получаю ошибку компилятора:
error: call of overloaded 'sin(ArithmeticF&)' is ambiguous
candidates are:
double sin(double)
const ArithmeticF arithmetic::sin(const ArithmeticF&)
Я никогда не использовал заголовок <math.h>
, только <cmath>
. Я никогда не использовал using namespace std
в файле заголовка.
Я использую gcc 4.6. *. Я проверил, что представляет собой заголовок, содержащий двусмысленное объявление, и он оказывается:
mathcalls.h:
Prototype declarations for math functions; helper file for <math.h>.
...
Я знаю, что <cmath>
включает <math.h>
, но он должен защищать объявления пространством имен std. Я вникаю в заголовок <cmath>
и нахожу:
cmath.h:
...
#include <math.h>
...
// Get rid of those macros defined in <math.h> in lieu of real functions.
#undef abs
#undef div
#undef acos
...
namespace std _GLIBCXX_VISIBILITY(default)
{
...
Итак, пространство имен std начинается после #include <math.h>
. Здесь что-то не так, или я что-то не понял?