Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ How to not use friend declaration when equipping a class with `operator<<`

#include <iostream>

class Point {
   private:
    double m_x{};
    double m_y{};
    double m_z{};

   public:
    Point(double x = 0.0, double y = 0.0, double z = 0.0)
        : m_x{x}, m_y{y}, m_z{z} {}

};

std::ostream& operator<<(std::ostream& out, const Point& point) {
    out << "Point";
    // Use public interface of point here.
    return out;
}

int main() {
    const Point point1{2.0, 3.0, 4.0};

    std::cout << point1 << '
';

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Stream Overloading 
Cpp :: 130 divided by -10 
Cpp :: convert preorder to postorder calculator 
Cpp :: c++ synchronization primitives example programs 
Cpp :: std::random_device 
Cpp :: Define and show the implementation of the functions of an arrayList. 
Cpp :: distructor of the node of the link list 
Cpp :: how to make a running text in c++ 
Cpp :: determining whether a array is a subsequence of another array 
Cpp :: c++ vector merge algorithm 
Cpp :: assert warning c++ 
Cpp :: graph colouring backtracking 
Cpp :: sin trigonometric function 
Cpp :: inverse elment of array c++ 
Cpp :: how to store array of string with spaces in c++ stl 
Cpp :: c++ programming 
Cpp :: std::string(size_t , char ) constructor: 
Cpp :: c++ arreglo/array 
Cpp :: c++ suare 
Cpp :: passing a 2d array cpp 
Cpp :: combination sum iv leetcode 
Cpp :: function template in c++ 
Cpp :: assignment operators 
Cpp :: c++ handling 
Cpp :: is the c++ 20 char te same as the old one 
C :: wireshark tls client hello filter 
C :: classification report to excel 
C :: express.static public 
C :: font awsome circle info icon 
C :: execute maven project in cmd 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =