我想为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'
答案 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
文件链接到您的执行文件?