2015-02-06 27 views
1

這是在下面的代碼已知的錯誤:「controlled_runge_kutta」不是類模板

「controlled_runge_kutta」不是類模板

在以下代碼:

template< 
class ErrorStepper , 
class ErrorChecker , 
class Resizer 
> 
class controlled_runge_kutta< ErrorStepper , ErrorChecker , Resizer , explicit_error_stepper_tag > 
{ 
public: 
}; 

int main() 
{ 
    return 0; 
} 

我知道爲什麼我得到這個錯誤。但我的問題是,它是如何工作在第146行的github的原始提升庫中?

謝謝。

回答

1

看線109

template< 
class ErrorStepper , 
class ErrorChecker = default_error_checker< typename ErrorStepper::value_type , 
typename ErrorStepper::algebra_type , 
typename ErrorStepper::operations_type > , 
class Resizer = typename ErrorStepper::resizer_type , 
class ErrorStepperCategory = typename ErrorStepper::stepper_category 
> 
class controlled_runge_kutta; 

現在,有模板類的聲明,在管線146有這個類的只是局部的專業化。

0

如果語法是:

template <template-parameters...> class NAME { ... }; 

那麼它是一個 「主模板定義」。如果是:

template <template-parameters...> class NAME<parameter-spec> { ... }; 

那麼它是一個局部模板特殊化(即定義的參數的特殊情況下的「映射」次定義

你不能聲明一個局部模板專業化,如果主模板定義。 (類或函數模板)的名稱還沒有提供。

所以,取決於你想要聲明的內容。如果只是一個模板 - 然後刪除所有在< ...>之後的類名稱。如果專業化,那麼請首先定義模板本身。

template<...>聲明在主定義和專業化中並不意味着相同。在主定義中,它定義了「簽名」(應該如何調用「實例化」),在專業化中,它只是提供了一些內部使用的名稱。