2012-11-19 5 views
1

사용자 정의 네임 스페이스로 복사 할 수없는 복사 가능 파일 (boost::noncopyable에서 상속)이 있습니다. 다음과 같이 또한, 나는 이전 하나를 사용하는 다른 클래스를 가지고 :템플릿 클래스의 noncopyable static const 멤버 클래스

이 코드는 (심지어 인스턴스없이) 다음 오류로 연결
#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_(); 

:

오류 : 'const를 custom_namespace의 custom_namespace_user :: custom_namespace_user '

다음 방법 custom_namespace_()'클래스에서 선언 된 멤버 함수는 '합법적되지 않습니다 :

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

이 두 클래스를 선언하려면 어떻게해야합니까? (처음에는 noncopyable static const member 클래스로 정의됩니다)? 이게 가능한가?

+0

왜 그냥 정적 멤버 함수를 사용하지 않는? 인스턴스가 실제로 필요합니까? – Pubby

+0

@ahenderson 네,하지만'custom_namespace'는'typedefs'와'F'에 의존하는 다른 특징을 가지고 있습니다. – Orient

+0

@Pubby이 관계없는 일. 이에 대한 대답은이 토론의 범위를 벗어납니다. – Orient

답변

3

코드가 개체 정의가 아닌 함수 선언으로 구문 분석됩니다.

이 솔루션은 괄호를 제거하는 것입니다

template< typename F > ::custom_namespace<F> const custom_namespace_user<F>::custom_namespace_; 
관련 문제