c ++初始化错误

时间:2016-11-22 02:16:08

标签: c++ initializer-list

我想为Coordinates声明一个类,我尝试这个代码:

  

Coordinate.h:

try/catch
     

Coordinate.cpp:

typedef unsigned short Short;
class Coordinate
{
private :
  Short _row;
  Short _col;
public:
  Coordinate(Short row, Short col);
  bool operator ==(const Coordinate* other);
};
     

Main.cpp:

#include "Coordinate.h"

Coordinate::Coordinate(Short row, Short col)
  : _row(row) , _col(col){}

bool Coordinate::operator== (const Coordinate* other)
{
  if (other == NULL || this == NULL)
      return false;
  if (this == other)
      return true;
  if (other->_row != this->_row || other->_col != this->_col)
      return false;
  return true;
}

但是visual studio 2015会返回错误:

  • 错误C2079'a'使用未定义的类'Coordinate'

  • 错误C2440'初始化':无法从'初始化列表'转换为 'INT'

3 个答案:

答案 0 :(得分:4)

修正您的拼写错误:

sudo yum install spark2

#include "Coordinate.h" int main() { Coodinate a( 2,2 ); } 应为Coodinate

答案 1 :(得分:0)

第一个错误是由于拼写错误的Coo r dinate。可能还会修复第二个。

答案 2 :(得分:0)

通常undefined表示编译器找不到Coordinate.cpp文件。您是否检查过项目设置,使链接器将Coordinate.cpp文件链接到您的执行文件?