I overloaded a cout and cin opeartor and when I tried to use it, it gave me an error like this:
1 IntelliSense: function "std::basic_ostream<_Elem, _Traits>::basic_ostream(const std::basic_ostream<_Elem, _Traits>::_Myt &)
[with _Elem=char, _Traits=std::char_traits<char>]"
(declared at line 84 of "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\ostream") cannot be referenced -- it is a deleted function
And here's the header file of my class:
#pragma once
#include <iostream>
class Point2D
{
private:
int m_X;
int m_Y;
public:
Point2D(): m_X(0), m_Y(0)
{
}
Point2D(int x, int y): m_X(x), m_Y(y)
{
}
friend std::ostream& operator<< (std::ostream out, const Point2D &point)
{
out << "(" << point.m_X << "," << point.m_Y << ")" << std::endl;
return out;
}
friend std::istream& operator>> (std::istream in, Point2D &point)
{
in >> point.m_X;
in >> point.m_Y;
return in;
}
int getX() const { return m_X; }
int getY() const { return m_Y; }
~Point2D();
};
So, basically, it's just a class that can return and set X and Y coordinates. And I overwrote <<
and >>
operators to make things easier.
But when I try to use it in the main function like this:
#include "stdafx.h"
#include <iostream>
#include "Point2D.h"
using namespace std;
int main(int argc, char * argv[])
{
Point2D point(7, 7);
cout << point; //there's an error here.
return 0;
}
There seems to be the error on this line:
cout << point;
What exactly am I doing wrong?