vs 2017 C 汇编问题

VS 2017 C++ compilation problems

本文关键字:问题 汇编 2017 vs      更新时间:2023-10-16

我对我的VS 2017都有问题。每次我更改class.cpp文件中的方法的主体(例如Matirice的乘法)时,我必须在MAIM函数中重写指令。IE。如果我有a = b * c;语句我必须删除并再次添加乘法符号在" test.cpp"中的主体,然后编译。否则,v将不会在我的方法中包括更改,并且会因为方法实施中根本没有更改。

预先感谢。

编辑这是我试图修复的代码:

template<typename T>
Mx::Matrix<T>::Matrix(unsigned rows, unsigned cols, T const & init_val)
{
    _matrix.resize(rows);
    for (unsigned i = 0; i < _matrix.size(); i++)
        _matrix[i].resize(cols, init_val);
    _rows = rows;
    _cols = cols;
}
template<typename T>
Mx::Matrix<T>::Matrix(Matrix<T> const & mx)
{
    _matrix = mx._matrix;
    _rows = mx.GetRows();
    _cols = mx.GetCols();
}
template<typename T>
Mx::Matrix<T> & Mx::Matrix<T>::operator=(Matrix<T> const & mx)
{
    if (this == &mx)
        return *this;
    unsigned new_rows = mx.GetRows();
    unsigned new_cols = mx.GetCols();
    _matrix.resize(new_rows);
    for (unsigned i = 0; i < _matrix.size(); i++)
        _matrix[i].resize(new_cols);
    for (unsigned i = 0; i < new_rows; i++) {
        for (unsigned j = 0; j < new_cols; j++) {
            _matrix[i][j] = mx(i, j); // musisz przeciazyc operator()()
        }
    }
    _cols = new_cols;
    _rows = new_rows;
    return *this;
}
template<typename T>
Mx::Matrix<T> Mx::Matrix<T>::operator+(Matrix<T> const & mx) const
{
    Mx::Matrix<T> temp(mx); // ALBO Mx::Matrix<T> temp(_rows, _cols, 0.0)
    for (unsigned i = 0; i < this->GetRows(); i++) {
        for (unsigned j = 0; j < this->GetCols(); j++) {
            temp(i, j) = (*this)(i, j) + mx(i, j); // ALBO this->_matrix[i][j]
        }
    }
    return temp;
}
template<typename T>
Mx::Matrix<T>& Mx::Matrix<T>::operator+=(Matrix<T> const & mx)
{
    return *this = *this + mx;
}
template<typename T>
Mx::Matrix<T> Mx::Matrix<T>::operator-(Matrix<T> const & mx) const
{
    Mx::Matrix<T> temp(mx); // ALBO Mx::Matrix<T> temp(_rows, _cols, 0.0)
    for (unsigned i = 0; i < this->GetRows(); i++) {
        for (unsigned j = 0; j < this->GetRows(); j++) {
            temp(i, j) = (*this)(i, j) - mx(i, j); // ALBO this->_matrix[i][j]
        }
    }
    return temp;
}
template<typename T>
Mx::Matrix<T>& Mx::Matrix<T>::operator-=(Matrix<T> const & mx)
{
    return *this = *this - mx;
}
template<typename T>
Mx::Matrix<T> Mx::Matrix<T>::operator*(Matrix<T> const & mx)
{
    unsigned rows = mx.GetRows();
    unsigned cols = this->GetRows();
    Mx::Matrix<T> temp(rows, cols, 0.0);
    for (unsigned i = 0; i < rows; i++) {
        for (unsigned j = 0; j < cols; j++) {
            for (unsigned k = 0; k < rows; k++) {
                temp(i, j) += (*this)(i, k) * mx(k, j);
            }
        }
    }
    return temp;}

,在此更改之后,我在这里(或项目中的任何地方)进行了一些愚蠢的删除语句(int main(int Main())的信,然后添加它,以便VS可以将我的更改包括在class.cpp文件中。..

您共享的代码来自class.cpp文件?正如 @manni66在对问题的评论中提到的那样,它必须全部都在标头文件中,或者至少包含在标头文件中。查看为什么仅在标题文件中实现模板?