noncopyable static const member class in template class

Posted by Dukales on Stack Overflow See other posts from Stack Overflow or by Dukales
Published on 2012-11-19T16:57:33Z Indexed on 2012/11/19 16:59 UTC
Read the original article Hit count: 236

I have a non-copyable (inherited from boost::noncopyable) class that I use as a custom namespace. Also, I have another class, that uses previous one, as shown here:

#include <boost/utility.hpp>
#include <cmath>

template< typename F >
struct custom_namespace
    : boost::noncopyable
{

    F sqrt_of_half(F const & x) const
    {
        using std::sqrt;
        return sqrt(x / F(2.0L));
    }

    // ... maybe others are not so dummy const/constexpr methods

};

template< typename F >
class custom_namespace_user
{

    static
    ::custom_namespace< F > const custom_namespace_;



public :

    F poisson() const
    {
        return custom_namespace_.sqrt_of_half(M_PI);
    }

    static
    F square_diagonal(F const & a)
    {
        return a * custom_namespace_.sqrt_of_half(1.0L);
    }

};

template< typename F >
::custom_namespace< F > const custom_namespace_user< F >::custom_namespace_();

this code leads to the next error (even without instantiation):

error: no 'const custom_namespace custom_namespace_user::custom_namespace_()' member function declared in class 'custom_namespace_user'

The next way is not legitimate:

template< typename F > ::custom_namespace< F > const custom_namespace_user< F >::custom_namespace_ = ::custom_namespace< F >();

What should I do to declare this two classes (first as noncopyable static const member class of second)? Is this feaseble?

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates