-3

I want to declare a class for Coordinates and I try this codes:

Coordinate.h:

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

Coordinate.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;
}

Main.cpp :

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

But visual studio 2015 returns this errors:

  • Error C2079 'a' uses undefined class 'Coordinate'

  • Error C2440 'initializing': cannot convert from 'initializer list' to 'int'

Community
  • 1
  • 1
Alireza
  • 18
  • 5

3 Answers3

4

Fix your typo in:

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

Coodinate should be Coordinate.

BUCH
  • 103
  • 4
  • 2
    @Alireza Can you show us the new compiler output to see the errors? It compiles fine on my system (Had to change NULL to 0 though for some reason). – BUCH Nov 22 '16 at 02:31
  • 1
    In C++, you [should be using `nullptr` instead of `NULL`](http://stackoverflow.com/a/13816448/1848578). – qxz Nov 22 '16 at 02:50
0

The first error is due to misspelled Coordinate. Might also fix the second one.

Henning Koehler
  • 2,456
  • 1
  • 16
  • 20
0

Usually undefined means that the compiler can not find the Coordinate.cpp file. Have you checked about your project setting that makes the linker link the Coordinate.cpp file into your execute file?

John Zeng
  • 1,174
  • 2
  • 9
  • 22