Home c++ class Point C++

class Point C++




Is there a class or structure Point (point) in stl or its equivalent?

Answer 1, authority 100%

As such, no.
If you need a point on the plane, you can use the pair & lt; & gt; structure, but it is not convenient enough (the fields are first and second , not x and y ).
You can use the same array with a fixed number of elements.

But the easiest is to write

struct Point {
  double x, y;

and do not suffer 🙂

Answer 2, authority 100%

“Dot” is a concept that is domain dependent . In mathematics, a point will be coordinates double, usually with two or three components, but in the general case, the number is arbitrary, and the name of the components may be different due to different coordinate systems. In Windows controls, there will be a point with two int coordinates, in some cases int16_t. In games, float points are most useful. In the console, the dot will be an unsigned int pair. And we do not yet consider the accompanying classes, for example, vectors and matrices, and the available operations between them.

As you can see, the points can be very different. In this regard, introducing a dot class into the STL is rather impractical: you will have to produce dozens of classes with different types, names and number of components, and their applicability will be very limited due to the lack of interaction with classes that are harmoniously combined with the dot class.

The point class can be found in libraries closer to subject areas, for example, for mathematical calculations, for controls, for game engines. Use them.

If you have something of your own, it will not be difficult to write your own trivial dot class & nbsp; – these are two lines of code.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions