c++ - 使用模板类时出现内部编译错误

标签 c++ visual-studio-2013 compiler-errors

我正在尝试将项目从 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(); 
}

传入一个名为 segment 的变量,代码尝试访问一个名为 segments 的变量。

尝试将参数名称更改为段。

关于c++ - 使用模板类时出现内部编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27346404/

相关文章:

asp.net - 如何解决错误189.dll和.dll中都存在 'XXX'类型

java - 为什么使用ArrayList但返回原始类型的方法要求该方法名称包含 “static”?

android - Cocos2dx 构建问题

c++ - __attribute__((__packed__)); 之间有什么区别?和#pragma pack(1)

c++ - 从字符串中删除两个字符以获得唯一字符的可能性

c++ - 分离类的最佳方式,VS 2013

c++ - 为什么 <iterator> 的 std::size 不能使用原始数组参数

c# - VS2013 更新 4,无法打开 CSHTML 文件

visual-studio-2013 - VS2013 Ultimate Preview + Web Essentials 2013 RC 不编译 LESS?

flutter - 添加 firebase 消息传递后编译错误