簡體   English   中英

使用模板類時的內部編譯錯誤

[英]internal compiling error when using template class

我正在嘗試將項目從VS2008遷移到VS2013,該項目在VS2008中編譯和工作,不幸的是我在使用VS2013編譯相同的代碼時突然收到“編譯器中發生內部錯誤”。 嘗試調用模板類的方法時發生錯誤

void func(const CMatrix<CSegment>& segments) const
{
    int row, col;
    row = segments.NumOfRows(); //error points to here
    col = segments.NumOfColumns(); // if I remove the above line then the error points to here
}

和CMatrix的定義如下:

class CBaseMatrix
{
public:
    CBaseMatrix() {};
    virtual ~CBaseMatrix() {};
    virtual void Resize(const int row, const int col) = 0;
    virtual inline int Size()   const = 0;
    virtual inline int NumOfColumns() const = 0;
    virtual inline int NumOfRows() const = 0;
};


template <class T> 
class CMatrix : public CBaseMatrix
{   
public:

    CMatrix() : 
    m_rawBuff(0),
    m_rawBuffSize(0), 
    m_columns(0), 
    m_rows(0), 
    m_data(0) 
    {};

CMatrix(const CMatrix& matrix):
{
    *this = matrix;
};

    inline int NumOfColumns()   const {return(m_columns);};

    inline int NumOfRows()  const {return(m_rows);};

    inline int Size()   const {return(m_data.size());};

private:
    int m_columns;
    int m_rows;
    vector<T> m_data;
    T*  m_rawBuff ;
    int m_rawBuffSize ;

};

我發現代碼沒有任何問題,錯誤本身並不是很有用。

我希望我能錯過某些東西,或者有人遇到類似的問題,並且知道如何解決它。

謝謝。

我不知道代碼如何在任何編譯器下工作:

void func(const CMatrix<CSegment>& segment) const
{
    int row, col;
    row = segments.NumOfRows(); //error points to here
    col = segments.NumOfColumns(); 
}

通過在一個變量被稱為片段和代碼試圖訪問一個稱為段s。

嘗試將參數名稱更改為段。

好吧,我發現了問題所在,請注意原始代碼:

CMatrix(const CMatrix& matrix):
{
    *this = matrix;
};

我在構造函數之后有“:”,但初始化列表為空,不知何故導致編譯器粉碎。

刪除后:

CMatrix(const CMatrix& matrix)
{
    *this = matrix;
};

一切正常!

請注意,我已將錯誤提交給Microsoft,並希望他們會在下次更新時處理此問題,但與此同時,我將解決方案保留在此處,以防其他人遇到此問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM