2017-09-23 97 views
-3

我的VS VS 2017有问题。每次我改变我的方法(例如matirces的乘法)在class.cpp文件中的主体,我必须在主函数中重写指令。 I.E.如果我有一个a = b * c;声明我必须删除并再次添加乘法符号int在“test.cpp”中的main,然后编译。否则,VS将不会在我的方法中包含更改,并且会在方法实现中根本没有任何更改。VS 2017 C++汇编问题

这个问题主体不符合我们的质量标准。请确保它完全描述了您的问题 - 包括您已经尝试的内容 - 并使用正确的语法编写。

在此先感谢。

编辑 这是代码即时通讯试图解决:

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主( ))并再次添加它,以便VS可以将我的更改包含在class.cpp文件中...

+0

请参考[参观](https://stackoverflow.com/tour),阅读[帮助页面](https://stackoverflow.com/help)并向我们显示相关代码。欢迎来到SO。 – Ron

+0

欢迎来到Stack Overflow。请回顾[我如何问一个好问题](https://stackoverflow.com/help/how-to-ask)。你的问题应该包括你的*特定*编码相关问题的清晰概述,你已经尝试过的内容以及[最小,完整和可验证示例]中相关代码的摘要(https://stackoverflow.com/help/mcve),所以我们有足够的信息能够提供帮助。 – FluffyKitten

+0

模板未在cpp中实现。 – 2017-09-23 14:46:51

回答