- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 Barton 和 Nackman 技巧来实现类以避免动态调度。 (我正在编写性能很重要的 MCMC 代码。)我不是 C++ 专家,但基本技巧在其他地方对我有用。但是,我现在有一个情况需要对第二个派生类进行模板化。这似乎会导致问题。我的代码大纲是:
// Generic step class
template<class DerivedStepType>
class Step {
public:
DerivedStepType& as_derived() {
return static_cast<DerivedStepType&>(*this);
}
void DoStep() {
return as_derived.DoStep();
}
};
// Gibbs step
template<class DerivedParameterType> // THIS IS THE PROBLEM
class GibbsStep : public Step<GibbsStep> {
public:
GibbsStep(DerivedParameterType new_parameter) {
}
void DoStep() {
}
};
问题是template<class DerivedParameterType>
和以下 <GibbsStep>
(来自巴顿和纳克曼的把戏)。使用 g++ v 4.01 (OSX),出现以下错误:
./src/mcmc.h:247: error: type/value mismatch at argument 1
in template parameter list for 'template<class DerivedStepType> class Step'
./src/mcmc.h:247: error: expected a type, got 'GibbsStep'
如果掉落,一切都可以正常编译 template<class DerivedParameterType>
并替换 DerivedParameterType
比如说,double
.
有什么想法吗?
最佳答案
GibbsStep 是一个模板类,在 public Step<GibbsStep>
中使用时需要实例化.您应该将其更改为 public Step<GibbsStep<DerivedParameterType> >
关于c++ - 模板化的 Barton 和 Nackman 技巧问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/954398/
来自维基百科: // A class template to express an equality comparison interface. template class equal_compar
我正在尝试使用 Barton 和 Nackman 技巧来实现类以避免动态调度。 (我正在编写性能很重要的 MCMC 代码。)我不是 C++ 专家,但基本技巧在其他地方对我有用。但是,我现在有一个情况需
什么是更可取的(如果有的话)? 变体 A(Barton-Nackman): template struct equal_comparable { friend bool operator ==
我已经阅读了很多关于 Reinforcement Learning 的内容最近,我找到了"Reinforcement Learning: An Introduction"成为一名出色的向导。作者的帮助
我是一名优秀的程序员,十分优秀!