I am trying to migrate a project from VS2008 to VS2013, The project compiles and works in VS2008, unfortunately I suddenly receive an "An internal error has occurred in the compiler" when compiling the same code with VS2013. The error occurs when trying the call a method of a template class
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
}
and CMatrix is defined like so:
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 ;
};
I cannot find any problem with the code, and the error itself is not very informative.
I hope that I miss something or that someone encountered a similar problem and has an idea how to solve it.
Thanks.
I have no idea how the code would work under any compiler as:
void func(const CMatrix<CSegment>& segment) const
{
int row, col;
row = segments.NumOfRows(); //error points to here
col = segments.NumOfColumns();
}
Passes in a variable called segment and the code tries to access one called segment s .
Try changing the parameter name to segments.
Well, I found out what the problem was, notice that in the original code:
CMatrix(const CMatrix& matrix):
{
*this = matrix;
};
I have ":" after the constructor, but the initialization list is empty, Somehow that caused the compiler to crush.
after removing them:
CMatrix(const CMatrix& matrix)
{
*this = matrix;
};
everything works!
Note that I submitted the error to Microsoft, and hopefully they will take care of this in the next update, but in the meanwhile, I leave my solution here in case anyone else encounter this problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.