I'm using the << operator, I've done some edits to my post above as there were some typos but my codes do have << operator.
So I have edited them as such:
Point2D.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#ifndef Point2D_h
#define Point2D_h
#include <iostream>
usingnamespace std;
class Point2D
{
public:
int x;
int y;
Point2D(int _x, int _y);
~Point2D();
};
ostream& operator<<(ostream& os, const Point2D& point)
{
os << "Point2D: " << " x=" << point.x << ", y=" << point.y;
return os;
}
Point2D.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include "pch.h"
#include "Point2D.h"
#include <string>
#include <string.h>
#include <cstdlib>
#include <iostream>
usingnamespace std;
Point2D::Point2D(int _x, int _y)
{
x = _x;
y = _y;
}
Point2D::~Point2D()
{
}
I'm not too sure if i am declaring them correctly but now Im getting :
binary '==': no operator found which takes a left-hand operand of type 'Point2D'
It not wrong to put the definition in the header, but your code will be more organized if you only put in the header those implementations that need to be in the header.