I am writing a C ++ class that represents an arithmetic type (C ++ wrapper around mpfr ), and I would like to support some of the functions found in <cmath> (Take std :: sqrt as an example).
So, I have the following class:
namespace ns
{
class MyClass
{
public:
friend MyClass sqrt(const MyClass& mc);
};
}
And I can use it as follows:
MyClass c;
MyClass d = ns::sqrt(c);
MyClass e = sqrt(c);
But I can not use it like this:
MyClass f = std::sqrt(c);
Compiler (g ++ (Debian 4.7.2-5)): "there is no corresponding function to call sqrt (ns :: MyClass &)".
This is normal, but for me it is a problem. I need this to be valid, because MyClass is supposed to be used in existing template functions (which I should not modify). For instance:
template <typename T>
void func(T a)
{
T c = std::sqrt(a);
}
int main()
{
func<float>(3);
func<MyClass>(MyClass(3));
}
The following code snippet really solves my problem:
namespace std
{
using ns::sqrt;
}
std . , .
? , ?
?