# In a class, why do you include the function that overloads the stream insertion operator, <<, as a friend function? (5, 6)

1 answer

###### Question:

In a class, why do you include the function that overloads the stream insertion operator, <<, as a friend function? (5, 6)

## Answers

Answer:To provide << operator access to non-public members of the class.Explanation:Whenever we overload << operator, an object to ostream class has to be passed as this is the class which has properties which allows printing of output to console. Moreover, this operator is used outside class all the time so if not made a global member it will produce conflicts so thats why it has to be made a friend function to allow efficient access to private members of the class. Its declaration inside class is as follows :friend ostream& operator<<(std::ostream& os, const T& obj) ;

#### Similar Solved Questions

1 answer

### Whose land did the samurai defend and protect?

Whose land did the samurai defend and protect?...

2 answers

### If (Negative 3) Superscript negative 5 Baseline = StartFraction 1 Over x EndFraction, what is the value of x? Negative 243 Negative StartFraction 1 Over 243 EndFraction StartFraction 1 Over 243 EndFraction 243

If (Negative 3) Superscript negative 5 Baseline = StartFraction 1 Over x EndFraction, what is the value of x?
Negative 243
Negative StartFraction 1 Over 243 EndFraction
StartFraction 1 Over 243 EndFraction
243...

2 answers

### Explain why heating a contained gas that is held at a constant volume increases its pressure.

Explain why heating a contained gas that is held at a constant volume increases its
pressure....

2 answers

### In this experiment we will observe the magnetic fields produced by a current carrying wire. A long wire is suspended vertically, passing through a horizontal platform. The wire is connected to a power supply, allowing a current of 5.0 Amps to flow. A compass is placed on the platform stand near the vertical wire. When no current is present in the wire, the compass needle points in the same direction any where around the wire due to the Earth’s magnetic field. When a current flows through the wir

In this experiment we will observe the magnetic fields produced by a current carrying wire. A long wire is suspended vertically, passing through a horizontal platform. The wire is connected to a power supply, allowing a current of 5.0 Amps to flow. A compass is placed on the platform stand near the ...

1 answer

### Which part of the Constitution was the most compelling reason for North Carolina's state convention to ratify the Constitution?

Which part of the Constitution was the most compelling reason for North Carolina's state convention to ratify the Constitution?...

1 answer

### Three students share a bag of garri in such a way that the first student took ¼ of the garri and the second ¾ of the remainder. what fraction of garri did the third student take?

three students share a bag of garri in such a way that the first student took ¼ of the garri and the second ¾ of the remainder. what fraction of garri did the third student take?...

1 answer

### Find the equation of the parabola with its focus at (-7,6) and its directrix at y = 4 OA) y-/a(x + 7)2 + 5 O B) y-/Ax+ 7)2 + 5 Ooy-/ax- 72 +5 OD) y- 1/4lx+ 5)2+7

Find the equation of the parabola with its focus at (-7,6) and its directrix at y = 4
OA) y-/a(x + 7)2 + 5
O B) y-/Ax+ 7)2 + 5
Ooy-/ax- 72 +5
OD) y- 1/4lx+ 5)2+7...

1 answer

### Which of the following has a primary responsibility for a live me alcohol from the bloodstream

Which of the following has a primary responsibility for a live me alcohol from the bloodstream...

1 answer

### Company A can borrow money at a fixed price of 7.5 percent or a variable rate set at prime plus 1 percent. Company B can borrow money at a variable rate of prime plus .5 percent or a fixed rate of 8 percent. Company A prefers a variable rate and Company B prefers a fixed rate. If the swap dealer requires .5 percent profit what would be a favorable outcome swap between Companies A and B?

Company A can borrow money at a fixed price of 7.5 percent or a variable rate set at prime plus 1 percent. Company B can borrow money at a variable rate of prime plus .5 percent or a fixed rate of 8 percent. Company A prefers a variable rate and Company B prefers a fixed rate. If the swap dealer req...

1 answer

### Enter your answer and show all the steps that you use to solve this problem in the space provided. Find the values of x and y.

Enter your answer and show all the steps that you use to solve this problem in the space provided. Find the values of x and y....

1 answer

### What heats up quicker air over land or air over the ocean?why?

What heats up quicker air over land or air over the ocean?why?...

2 answers

### Decide whether the sentence is correct or incorrect as written. El perro comió la comida. correct incorrect

Decide whether the sentence is correct or incorrect as written. El perro comió la comida. correct incorrect...

2 answers

### 214 out of 450 students went to a concert, what percent did not go?

214 out of 450 students went to a concert, what percent did not go?...

1 answer

### 16. The laws of physics state that energy _____. cannot be destroyed can be created originates as heat is electrical

16.
The laws of physics state that energy _____.
cannot be destroyed
can be created
originates as heat
is electrical...

1 answer

### If the weight of 2,290 steel balls is 3.18 kg, find the number of balls in 8.87 kg. Round the answer to the nearest integer, the nearest ball.

If the weight of 2,290 steel balls is 3.18 kg, find the number of balls in 8.87 kg.
Round the answer to the nearest integer, the nearest ball....

1 answer

### A total of h males and (h - 2) females visit the museum on a certain day. If total of visitors for that day is 80, what is the value of h? A. 38 С. 40 B. 39 D. 41

A total of h males and (h - 2) females visit the museum on a certain day. If total of visitors for that day is 80, what is the value of h? A. 38 С. 40 B. 39 D. 41...

2 answers

### According to the passage free will suscribes behavior such as

According to the passage free will suscribes behavior such as...