【发布时间】:2016-09-19 00:20:56
【问题描述】:
我试图找出从另一个调用模板专业化函数。在接下来的短片中,我尝试从 RED 调用 BLACK 特定函数。我收到以下编译器错误
无法调用成员函数bool noClass<color>::_open() [with Colors color = (Colors)2]’ without object
这很有意义。如何(或我可以)从 RED 呼叫 BLACK 工作?下面的代码段来自 noClass C++ 标头。
#ifndef COLORS_H
#define COLORS_H
enum class Colors { RED, GREEN, BLACK };
#endif /* COLORS_H */
#ifndef NOCLASS_H
#define NOCLASS_H
template <Colors color>
class noClass {
public: bool Open ( );
protected: bool _open ( );
};
template <Colors color> bool noClass<color>::Open ( ) { return noClass<color>::_open ( ); }
template <Colors color> bool noClass<color>::_open ( ) { return true; }
template <> inline bool noClass<Colors::BLACK>::_open ( ) { return true; }
template <> inline bool noClass<Colors::RED>::_open ( ) { return noClass<Colors::BLACK>::_open( ); }
#endif /* NOCLASS_H */
【问题讨论】:
标签: c++ templates specialization