枚举类型的限定过多
Excessive qualifying of an enum type
在此代码中
template<typename ValueT, typename ErrorT = bool>
class ValueOrError
{
private:
enum class State
{
Undefined, OK, EndOfFile, InError
};
public:
........
template<typename U>
static ValueOrError
copyProblem(const ValueOrError<U, ErrorT>& other)
{
ValueOrError result;
result.error_ = other.error_;
result.state_ = other.state_;
// result.state_ = static_cast<State>(other.state_);
return result;
}
private:
template<typename U, typename E>
friend class ValueOrError;
State state_;
ValueT value_;
ErrorT error_;
};
g++ 4.8.3在状态赋值时给出了一个错误。它抱怨不能分配类型为ValueError<U>::State
的值为不同U和T的ValueError<T>::State
类型值。静态强制类型转换绕过了这个问题。有更好的方法吗这样做呢?State类型显然不会随模板而变化参数。
这是一个方法:
struct State
{
enum Enum{ Undefined, OK, EndOfFile, InError };
};
template< class ValueT, class ErrorT = bool>
class ValueOrError
: private State
{
public:
相关文章:
- 在有符号基础类型枚举的位域上溢出
- 在编译时将强类型枚举器转换为其基础类型?
- 如果 int 是"not within the enums range",为什么将 int 转换为强类型枚举会编译?
- 类型枚举的变量不是类型名称
- 强类型枚举的语法实现错误
- 枚举与强类型枚举
- 错误:T没有命名类型-用于使用强类型枚举的专门化
- 如何使用强类型枚举
- QT:将强类型枚举参数传递到插槽
- 在类定义中声明类型(枚举、结构等)会增加代码大小
- Visual Studio 11 (beta) 中的强类型枚举类
- 使用强类型枚举对类型和子类型进行建模
- 不允许将强类型枚举用作同一基础类型的参数
- 如何正确使用C++强类型枚举
- 带有强类型枚举的模板参数推导
- 是否可以在googleprotobuf中为类型(枚举或消息)定义一个别名
- C++中默认初始化的全局强类型枚举是什么
- std::is_signed不适用于强类型枚举:int
- 如何定义自定义值的类型?(枚举类型定义)
- 将强类型枚举传递给函数