Language: C++

#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ESP (1e-10)
using namespace std;

typedef struct Point {
	double x; 
	double y;

	Point() { }

	Point(double x, double y) :x(x), y(y) { }

	Point operator+(Point& p) {
		return Point(x + p.x, y + p.y);
	}

	Point operator-(Point& p) {
		return Point(x - p.x, y - p.y);
	}

	Point operator*(double& a) {
		return Point(x*a, y*a);
	}

	Point operator=(Point& p1) {
		return Point(p1.x,p1.y);
	}

};

typedef Point Vector;

 struct Line {
	Point p1, p2;
	Line() {}
	Line(const Point& a,const Point& b) : p1(a),p2(b) { }
};

 typedef Line Segment;

double abs(Point p1, Point p2) {
	double norm = (p1.x - p2.x)*(p1.x - p2.x) + (p1.y - p2.y)*(p1.y - p2.y);
	return sqrt(norm);
}

double product(Vector v1, Vector v2) {
	return v1.x*v2.x + v1.y*v2.y;
}

double cross(Vector p1, Vector p2) {
	return p1.x*p2.y - p1.y*p2.x;
}

int ccw(Point p0, Point p1, Point p2) {
	Vector v0 = p1 - p0;
	Vector v1 = p2 - p0;
	if (cross(v0, v1) > ESP) return 1;   //p0,p1,p2??????????¨???????
	if (cross(v0, v1) < -ESP) return -1;   //p0,p1,p2???????¨???????
	if (product(v0, v1) < -ESP) return 2;  //p2,p0,p1????????§????????´??????
	if (abs(p0, p1) < abs(p0, p2)) return -2;  //p0,p1,p2????????§????????´??????
	return 0;   //p2?????????(p0,p1)???
}

bool intersect(Point p0, Point p1, Point p2, Point p3) {
	return (ccw(p0, p1, p2)*ccw(p0, p1, p3) <= 0&&ccw(p2,p3,p0)*ccw(p2,p3,p1)<=0);
	//?????????????????????????????¶
}

bool intersect(Segment s1, Segment s2) {
	return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

double DistanceLP(Line l, Point p) {
	return abs(cross(l.p2 - l.p1, p - l.p1)/abs(l.p1,l.p2));
}

double DistanceSP(Segment s, Point p) {
	if (product(s.p2 - s.p1, p - s.p1) < 0.0) return abs(p, s.p1);
	if (product(s.p1 - s.p2, p - s.p2) < 0.0) return abs(p, s.p2);
	return DistanceLP(s, p);
}

double DistanceSS(Segment s1, Segment s2) {
	if (intersect(s1, s2)) return 0.0;
	return min(min(DistanceSP(s1, s2.p1), DistanceSP(s1,s2.p2)), min(DistanceSP(s2, s1.p1), DistanceSP(s2, s1.p2)));
}

Point CrossPoint(Segment s1,Segment s2) {
	double d1=DistanceSP(s2, s1.p1);
	double d2 = DistanceSP(s2, s1.p2);
	double t = d1 / (d1 + d2);
	return s1.p1 + (s1.p2 - s1.p1)*t;

}

int main() {
	Segment s0,s1;
	int q; 
	cin >> q;
	for (int i = 0;i < q;i++) {
		cin >> s0.p1.x; cin >> s0.p1.y;
		cin >> s0.p2.x; cin >> s0.p2.y;
		cin >> s1.p1.x; cin >> s1.p1.y;
		cin >> s1.p2.x; cin >> s1.p2.y;
		Point x = CrossPoint(s0,s1);
		cout <<setprecision(20)<<x.x<<" "<<x.y<<endl;
	}
}

Compiler output:
a.cc:8:1: warning: 'typedef' was ignored in this declaration
    8 | typedef struct Point {
      | ^~~~~~~
a.cc: In function 'Point CrossPoint(Segment, Segment)':
a.cc:95:22: error: no match for 'operator+' (operand types are 'Point' and 'Point')
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                ~~~~~ ^ ~~~~~~~~~~~~~~~~~
      |                   |                   |
      |                   Point               Point
a.cc:16:15: note: candidate: 'Point Point::operator+(Point&)' (near match)
   16 |         Point operator+(Point& p) {
      |               ^~~~~~~~
a.cc:16:15: note:   conversion of argument 1 would be ill-formed:
a.cc:95:39: error: cannot bind non-const lvalue reference of type 'Point&' to an rvalue of type 'Point'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                        ~~~~~~~~~~~~~~~^~
In file included from /usr/include/c++/14/string:48,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)'
  627 |     operator+(typename reverse_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:627:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   'Point' is not derived from 'const std::reverse_iterator<_Iterator>'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)'
 1798 |     operator+(typename move_iterator<_Iterator>::difference_type __n,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1798:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   'Point' is not derived from 'const std::move_iterator<_IteratorL>'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
In file included from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3598 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3598:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   'Point' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3616 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3616:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   mismatched types 'const _CharT*' and 'Point'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3635 |     operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3635:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   'Point' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)'
 3652 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3652:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   'Point' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)'
 3670 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3670:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   'Point' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)'
 3682 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3682:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   'Point' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3689 |     operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3689:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   'Point' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3696:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3696 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3696:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   'Point' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3719:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3719 |     operator+(const _CharT* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3719:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   mismatched types 'const _CharT*' and 'Point'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3726:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)'
 3726 |     operator+(_CharT __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3726:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   'Point' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3733:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*)'
 3733 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:3733:5: note:   template argument deduction/substitution failed:
a.cc:95:40: note:   'Point' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>'
   95 |         return s1.p1 + (s1.p2 - s1.p1)*t;
      |                                        ^
/usr/include/c++/14/bits/basic_string.h:3740:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, _CharT)'
 3740 |     operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
      |     ^~~~~~~~
/usr/incl