1

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?

4

1 に答える 1

3

コードは、オブジェクト定義ではなく、関数宣言として解析されています。

解決策は、括弧を取り除くことです:

template< typename F > ::custom_namespace< F > const custom_namespace_user< F >::custom_namespace_;
于 2012-11-19T17:02:51.517 に答える