Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class ClassB
- {
- void bFunction() {/* тело функции */};
- };
- class ClassName
- {
- // определение класса
- friend void nonMemberFunction(); // 1
- friend void ClassB::bFunction(); // 2
- };
- void nonMemberFunction() {/* тело функции */ }
- class Point
- {
- int x;
- int y;
- public:
- Point() = default;
- Point(int pX, int pY) : x{ pX }, y{ pY } {}
- Point& setX(int pX) { x = pX; return *this; }
- Point& setY(int pY) { y = pY; return *this; }
- int getX()const { return x; }
- int getY()const { return y; }
- void showPoint() const
- {
- std::cout << '(' << x << ',' << y << ')';
- }
- friend double distance(const Point& p1, const Point& p2);
- };
- double distance(const Point& p1, const Point& p2)
- {
- auto xLength{ p2.x - p1.x };
- auto yLength{ p2.y - p1.y };
- return sqrt(xLength * xLength + yLength * yLength);
- }
- int main()
- {
- Point p1{ 5,5 };
- Point p2{ 10,10 };
- std::cout << "Distance between p1 and p2 is: " << distance(p1, p2) << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement