我有这样的代码:
#include<type_traits>
enum class DataFormat : int8_t
{
cDouble = 0,
cFloat = 1,
cChar = 2,
cBool = 3
};
class MatrixBase
{
protected:
MatrixBase(DataFormat const aDataFormat) : _dataFormat(aDataFormat) {}
public:
DataFormat getFormat() const { return _dataFormat; }
private:
DataFormat _dataFormat;
};
template<typename tType>
class Matrix final : public MatrixBase
{
private:
struct DataFormatBool { static constexpr DataFormat _csValue = DataFormat::cBool; };
struct DataFormatFloat { static constexpr DataFormat _csValue = DataFormat::cFloat; };
struct DataFormatDouble { static constexpr DataFormat _csValue = DataFormat::cDouble; };
using ActualDataFormat = typename std::conditional<std::is_same<tType, bool>::value, DataFormatBool,
std::conditional < std::is_same<tType, float>::value, DataFormatFloat, DataFormatDouble>>::type;
static_assert(std::is_same<tType, bool>::value || std::is_same<tType, float>::value || std::is_same<tType, double>::value, "Matrix supports only bool, float or double.");
public:
Matrix()
: MatrixBase(ActualDataFormat::_csValue)
{ }
};
DataFormat rrr() {
Matrix<bool> m;
return m.getFormat();
}它在哥德波特下编译,但在VS2019下不编译。(在那里它更大。)错误是
模型-stl\include\matrix.h(46,52):error C2039:'_csValue':不是'std::conditional‘的成员。
我做错什么了?
发布于 2021-06-18 10:28:22
将rrr的声明更改为
Matrix<float> m;在所有编译器上导致编译失败:
缺少从内部std::conditional提取结果类型。这应该是:
using ActualDataFormat =
typename std::conditional<std::is_same<tType, bool>::value,
DataFormatBool,
typename std::conditional<
std::is_same<tType, float>::value,
DataFormatFloat,
DataFormatDouble>::type
>::type;https://stackoverflow.com/questions/68033075
复制相似问题