2017-09-23 82 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

回答