小编mas*_*oud的帖子

Matrix中的'operator*'没有匹配运算符

我有一个矩阵类,如下所示:

template <size_t M, size_t N, typename T>
class Matrix
{
public:
    Matrix<M, N, T> operator +(const Matrix<M, N, T>& B) const;
    template <size_t P> Matrix<M,P,T> operator*(const Matrix<N, P, T>& B) const;
    template <typename T2> operator T2() const;  

private:
  T data[M][N];
};

// ... the body is in header file too  ...//
Run Code Online (Sandbox Code Playgroud)

身体写得很好,一切都运作良好.当我定义两个矩阵时如下:

Matrix < 10, 10, int> m1;
Matrix < 10, 10, float> m2;

m1 + m2;  // OK
m1 * m2;  // error: no match for 'operator*' in …
Run Code Online (Sandbox Code Playgroud)

c++ templates casting operators

0
推荐指数
1
解决办法
1742
查看次数

复制位模式:浮动到uint32_t

float值的位模式复制到a uint32_t或反之亦然(不是将它们转换),我们可以使用std::copy或者逐字节复制位memcpy.另一种方法是使用reinterpret_cast如下:

float f = 0.5f;
uint32_t i = *reinterpret_cast<uint32_t*>(&f);
Run Code Online (Sandbox Code Playgroud)

要么

uint32_t i;
reinterpret_cast<float&>(i) = 10;
Run Code Online (Sandbox Code Playgroud)

然而,有一个声称reinterpret_cast上面使用的两个,调用未定义的行为.

真的吗?怎么样?

c++ primitive-types undefined-behavior reinterpret-cast

0
推荐指数
1
解决办法
378
查看次数

在C++中创建指针类型的STL队列

我似乎无法弄清楚为什么这不起作用.我试图建立一个指针类型的队列,但它失败了.我有一个教室,我想要排队指向Room ..所以我做了:

queue<*Room> bfsRooms;
Run Code Online (Sandbox Code Playgroud)

这给了我错误:

`*'不能出现在常量表达式中

这是否意味着不可能创建指针的STL队列?

c++ queue pointers stl

-2
推荐指数
1
解决办法
4064
查看次数

什么是Swift中的"cin"(在C++中)命令?

什么是相当于statment cin >> x(在C++中),在Swift中要求用户从键盘输入一些值.如何用Swift语言实现这一目标?

swift

-16
推荐指数
1
解决办法
2380
查看次数