Header.h


#pragma once

#include <vector>

#include <map>

#include <memory>

#ifndef __HEADER__

#define __HEADER__


class Point

{

private:

const int x;

const int y;

public:

Point(const int&, const int&);

int getPointX(void) const;

int getPointY(void) const;

};

class Square

{

private:

std::map<int, std::vector<Point>> points;

const Point lowerLeftPoint;

const Point higherRightPoint;

public:

Square(const int&, const int&, const int&, const int&);

void PointMaker(const Point&, const Point&);

auto getPoint(const int& key) const;

void remover(int, const std::vector<Point>::iterator);

Point getLowerLeftPoint(void) const;

Point getHigherRightPoint(void) const;

int CalculateArea(void) const;

std::shared_ptr<Square> newSquare(const std::shared_ptr<Square>);

~Square();

};

int testNumInput(void);

#endif




definition.cpp


#include "header.h"

#include <vector>

#include <memory>


Point::Point(const int& input_x, const int& input_y) : x(input_x), y(input_y) {}

int Point::getPointX(void) const { return x; }

int Point::getPointY(void) const { return y; }

Point Square::getHigherRightPoint() const {return higherRightPoint;}

Point Square::getLowerLeftPoint() const {return lowerLeftPoint;}

Square::Square(const int& point1_x, const int& point1_y, const int& point2_x, const int& point2_y)

:lowerLeftPoint(point1_x, point1_y), higherRightPoint(point2_x, point2_y)

{

Point point1(point1_x, point1_y);

Point point2(point2_x, point2_y);

PointMaker(point1, point2);

}

void Square::PointMaker(const Point& lowerLeftPoint, const Point& higherRightPoint)

{

for (int i = lowerLeftPoint.getPointX(); i < higherRightPoint.getPointX(); i++)

{

for (int j = higherRightPoint.getPointY(); j < higherRightPoint.getPointY(); j++)

{

Point point(i, j);

points[i].push_back(point);

}

}

}

void Square::remover(int x, const std::vector<Point>::iterator y)

{

points[x].erase(y);

}

auto Square::getPoint(const int& key) const {return points.at(key);}

Square::~Square()

{

points.clear(); 

}

std::shared_ptr<Square> Square::newSquare(const std::shared_ptr<Square> addedSquare)

{

std::vector<std::unique_ptr<Point>> overlappingPoints;

if (lowerLeftPoint.getPointX() >= addedSquare->getHigherRightPoint().getPointX() ||

higherRightPoint.getPointX() <= addedSquare->getLowerLeftPoint().getPointX() ||

lowerLeftPoint.getPointY() >= addedSquare->getHigherRightPoint().getPointY() ||

higherRightPoint.getPointY() <= addedSquare->getLowerLeftPoint().getPointY())

return nullptr; //this case the two squares are not related in any theoratical way

else

{

for (auto it = points.begin(); it != points.end(); it++)

{

if (!addedSquare->getPoint(it->first).empty()) //if in the new square there is an x value same as the current square

{

for (auto it2 = points.at(it->first).begin(); it2 != points.at(it->first).end(); it2++)

{

if (std::find(addedSquare->getPoint(it->first).begin(), addedSquare->getPoint(it->first).end(),

[](std::unique_ptr<Point> point) {return point->getPointY(); }) != addedSquare->getPoint(it->first).end())

{

overlappingPoints.push_back(std::make_unique<Point>(it->first, it2->getPointY()));

remover(it->first, it2);

addedSquare->remover(it->first, it2);

}

}

}

}

return std::make_shared<Square>(overlappingPoints.front()->getPointX(),

overlappingPoints.front()->getPointY(),

overlappingPoints.back()->getPointX(),

overlappingPoints.back()->getPointY());

}

}

int Square::CalculateArea() const

{

int area = 0;

for (auto it = points.begin(); it != points.end(); it++)

{

area += it->second.size();

}

return area;


}




Source.cpp


#include <iostream>

#include <cstdio>

#include <vector>

#include <memory>

#include "Header.h"

#include <algorithm>

//#include <gtest/gtest.h>


int main(int argc, char ** argv)

{

//testing::InitGoogleTest(&argc, argv);


int testNum = 0;

int numOfSquares = 0;

std::vector<std::shared_ptr<Square>> squares;

std::vector<int> area;

std::vector<int> results;


testNum = testNumInput();


for (int i = 0; i < testNum; i++)

{

scanf("%d", &numOfSquares);


for (int j = 0, pos1_x, pos1_y, pos2_x, pos2_y; j < numOfSquares; j++)

{

scanf("%d %d %d %d", &pos1_x, &pos1_y, &pos2_x, &pos2_y);

squares.push_back(std::make_shared<Square>(pos1_x, pos1_y, pos2_x, pos2_y));

for (int k=0; k!=squares.size(); k++)

{

std::shared_ptr<Square> divisionResult;;

if (divisionResult != nullptr)

squares.push_back(divisionResult);

}

}

for (int j = 0; j < squares.size(); j++)

area.push_back(squares.at(j)->CalculateArea());


results.push_back(squares.size());

results.push_back(*std::max_element(area.begin(), area.end()));

}

for(auto it=results.begin(); it!= results.end(); it += 2)

{

std::cout << *it << " " << *(it + 1) << std::endl;

}

//return RUN_ALL_TESTS();

return 0;

}

int testNumInput(void)

{

int testNum;

do //test number input and checking loop

{

std::cin >> testNum;

if (testNum > 10)

std::cout << "test case number must be less than 10";

} while (testNum > 10);

return testNum;

}



이게 소스 전문,

In file included from c:\mingw\include\c++\4.8.3\vector:60:0,
                 from Header.h:2:
c:\mingw\include\c++\4.8.3\bits\stl_algobase.h: In instantiation of 'static _OI std::__copy_move<true, false, std::random_access_iterator_tag>::__copy_m(_II, _II, _OI) [with _II = Point*; _OI = Point*]':
c:\mingw\include\c++\4.8.3\bits\stl_algobase.h:390:70:   required from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = true; _II = Point*; _OI = Point*]'
c:\mingw\include\c++\4.8.3\bits\stl_algobase.h:428:38:   required from '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = true; _II = __gnu_cxx::__normal_iterator<Point*, std::vector<Point> >; _OI = __gnu_cxx::__normal_iterator<Point*, std::vector<Point> >]'
c:\mingw\include\c++\4.8.3\bits\stl_algobase.h:492:47:   required from '_OI std::move(_II, _II, _OI) [with _II = __gnu_cxx::__normal_iterator<Point*, std::vector<Point> >; _OI = __gnu_cxx::__normal_iterator<Point*, std::vector<Point> >]'
c:\mingw\include\c++\4.8.3\bits\vector.tcc:138:2:   required from 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(std::vector<_Tp, _Alloc>::iterator) [with _Tp = Point; _Alloc = std::allocator<Point>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<Point*, std::vector<Point> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = Point*]'
definition.cpp:30:19:   required from here
c:\mingw\include\c++\4.8.3\bits\stl_algobase.h:354:18: error: use of deleted function 'Point& Point::operator=(Point&&)'
        *__result = std::move(*__first);
                  ^
Header.h:8:7: note: 'Point& Point::operator=(Point&&)' is implicitly deleted because the default definition would be ill-formed:
 class Point
       ^
Header.h:8:7: error: non-static const member 'const int Point::x', can't use default assignment operator
Header.h:8:7: error: non-static const member 'const int Point::y', can't use default assignment operator



이게 gcc 에러 코드


Point& Point::operatr= 이 에러가 어디서 왜 발생하는지 잘 모르겠음