Welcome to the session on operator overloading. At the end of this session, student will be able to write C++ program to overload operator. This video is in continuation with my previous videos on compile time polymorphism and operator overloading part 1. Let's see an example of overloading binary operator as a member function. The class name is distance. It has two data members, feet and inch of type integer. Operator plus is a member function which accepts an object by reference. It performs the addition of two objects and stores the result in third object d3. As we know, food comprises of 12 inches. So, if inch is greater than or equal to 12, we divide it by 12 and add the quotient to feet and remainder is stored in inch and then the object d3 is returned. The statement d3 equal to d1 plus d2 is equivalent to d1 dot operator plus d2. It calls operator plus function. We can overload an operator by using a non-member function which is usually a friend of the class. Since a friend function is not a member of the class, it does not have a this pointer. So, operands are explicitly passed to an overloaded friend operator function. Let's see an example of overloading binary operator plus as a friend function. It is declared with friend keyword and defined outside class without using scope resolution operator. The operator plus function accepts two objects by reference, adds the values and stores the result in third object d3 and returns d3. The statement d3 equal to d1 plus d2 is equivalent to operator plus d1 comma d2. It calls friend function and adds the values of d1 and d2. If overloading an operator by using a friend or member function makes no functional difference, then it is usually best to overload by using member function. However, there is a situation in which overloading by using a friend function increases the flexibility of an overloaded operator. Let's examine this case now. As we know, when we overload a binary operator by using a member function, the object on the left side of the operator generates the call to the operator function. Further, a pointer to that object is passed as this pointer. Now, assume a class called cl that defines a member operator plus function that adds an object of the class to an integer. Given an object of the class called ob, the expression ob plus 100 is valid. In this case, ob generates the call to the overloaded plus operator function and the addition is performed. But what happens if the expression is written as 100 plus ob? In this case, an integer appears on the left. Since an integer is a built-in type, no operation between an integer and an object ob is defined. Therefore, the compiler will not compile this expression. To always position the object on the left could be a significant burden. The solution to the preceding problem is to overload addition using a friend. Do not use a member function in such case. Friend functions permit operators to be commutative. An operator is commutative if the result is same regardless of the order of its operands. Examples are addition, multiplication, etc. Both arguments are explicitly passed to the friend operator function. As we know, object plus integer has the same meaning as integer plus object. Therefore, to allow both object plus integer and integer plus object, simply overload the function twice. One version for each situation. Thus, when we overload an operator by using two friend functions, the object may appear on either the left or right side of the operator. Let's see an example of commutative friend function. A program has class distance. It has two data members, feet and inch. It has two constructors, default and parameterized constructor. A display function to display the values. Two overloaded plus operator functions. These are friend functions. First function accepts parameters distance by reference and integer. And the second friend function accepts parameters integer and distance by reference. D1 and D2 are objects. When D1 is constructed, a parameterized constructor gets called and values 8 and 9 are assigned to feet and inch respectively. When D2 is constructed, a default constructor gets called and it initializes the values of feet and inch to 0. The statement D2 equal to 100 plus D1 calls overloaded operator plus function with integer and distance parameters. T will have value 100 and X will refer to object D1. A temporary object D3 is constructed. D3 dot feet equal to X dot feet plus T. X dot feet is 8 because D1 and X both are same. X dot feet is 8, 8 plus 100, 108 and X dot inches 9. 9 plus 100 is 109. These values are stored in D3 dot feet and inch respectively. As we know, one foot is 12 inches. So here we are checking if D3 dot inch is greater than or equal to 12. And we are dividing total inches by 12 so that we will get the quotient and that quotient is added to feet. And the remainder is stored in inch and the object D3 is returned and that will be assigned to object D2. Now D2 dot display will call a display function and it will display the feet and inch of object D2. Now the statement D2 equal to D1 plus 200. It calls overloaded operator plus function with distance and integer parameter. Now X refers to D1 and T has value 200. Now again the same operation is performed. The object D3 is returned and it is assigned to object D2. D2 dot display will display feet and inches. Let's see the output of this program. Total feet and inches 117 feet 1 inch. Total feet and inches 225 feet 5 inches. Now let's see the concept of overloading stream insertion and stream extraction operators. These operators are overloaded to perform input output for user defined types. Left operand is of type O stream or I stream. I stream and O stream are classes. If an operator is overloaded as a member function, it must be a member of the class whose object is specified on the left side of the operator. For example, consider the statement object1 plus object2. Let object1 and object2 be objects of two different classes. To make this statement compile, we must overload plus in class of object1 or make operator plus a friend function. Operator insertion or extraction function must be a non-member function because left operand is not an object of user defined class. It must be a friend function to access private data members. Input and output operations can be performed on user defined types the same way as built-in types. D1 is an object of distance class. C in extraction D1 gets the input and C out insertion D1 displays it. We have used object D1 in input and output statements just like variables of built-in types. This can be done by overloading the operators, extraction and insertion. Let's see an example of overloading insertion and extraction operators. A distance class, data members feet and inch, two constructors and two operator functions. First operator function is operator insertion function which is a friend function. And the other operator function is operator extraction which is also a friend function. Now when object D1 is constructed, a parameterized constructor is called and it initializes feet and inches to 12 and 10 respectively. When object D2 is constructed, a default constructor gets called and it initializes 0 to both feet and inches. Then a statement enter the values of object D2 is displayed. C in extraction D2 calls operator extraction and the first parameter is I stream by reference input and the second parameter is distance by reference D. Here D refers to D2 and we are getting the input from user for feet and inches and return input. We are returning the reference of I stream class because we can combine the extractions like C in D1, extraction D2. Now a statement C out insertion D1 calls operator insertion function. The first parameter is O stream by reference output and the other parameter is distance by reference D. D refers to D1 and D dot feet and D dot inches is printed and the reference to O stream class is written because we can combine the insertions like C out D1 insertion D2. C out insertion D2 once again calls the operator insertion function and it displays the values for object D2. Now let's see the output. First I have to enter the values for object D2. I have entered 2 for feet and 4 for inches. So for object D1 the feet is 12 and inches 10 for object D2 feet is 2 and inches 4. Now pause the video for some time and overload operator equal to equal to in the given code to make the program error free. Once you have done this you may resume the video. The answer is shown here. The statement B1 equal to equal to B2 calls operator equal to equal to function. As operator equal to equal to is a member function object B1 is passed implicitly. Object B2 is passed by reference. The class has a data member capacity of type integer. If capacity of object B1 is equal to capacity of object B2 it returns 1 else returns 0. If return value is 1 equal is printed else not equal is printed. In this video we have seen the concept of operator overloading. Thank you.


to get underway reports to the ranch. Make controls as chief of duty reporting A division man and ready to get underway. Registration system is a medical department for a man and ready for getting underway. That's why the department's ready to get underway. The department takes the regulator up. Why don't we go? Registral division is ready to get underway. DC Central reporting man and ready for getting underway. Her name is USS California. The sixth Navy ship to bear the name. She first left this port under sail a century ago. Now the old sloop's namesake sails from Norfolk, powered not by the wind, but by the atom. Her designation, cruiser. But the only thing old about her is the name. She's the first of a new class of nuclear-powered surface ships. 11,000 tons of the most sophisticated systems yet designed by man. Her crew? 28 officers and 512 enlisted men. Among them is a small company of men without whom California could not make its first major voyage. Some say they're rugged individualists who sail their own course. Others say they're the backbone of the Navy. Probably they're both. They are the chief petty officers, the chiefs. And this is their story. Cucula 270. Cucula 270. Cape Henry 325. Cape Henry 325. Okay, take these two. Cucula 220. Omega. Radar. We'll get them all together. I'm going to knock them off. Okay. California clears the harbor and reaches out toward the open sea. Ahead lies the Caribbean and her first real challenge is a ship of the line. There are questions to be answered. How will her new systems perform? How will her crew perform? The questions will be answered soon on the high seas. This is the chief's mess. No one would dare enter this intersanctum without knocking. Not the newest seamen, not the captain. Such is the respect these men have earned. The chief is the highest ranking enlisted man in the Navy at the top of his profession. A board ship he occupies a position between the crew and the officers. A conduit between the two. Indispensable to both. If a ship were a corporation, the chief would be middle management. And just as middle management runs the day-to-day affairs of a corporation, the chief runs the ship. Strangely enough, there is no written document that defines the unique role of a chief in the Navy. His role for 200 years has been guided by tradition, common sense, and the constantly changing needs of his men and his officers. Master Chief Quartermaster, Kenneth Kimball, the assistant navigator. Although he never went to navigation school, he has mastered his profession through self-study and experience, and is taught it to many of the officers now in the fleet. When California's captain was assigned to the ship, he went looking for Kimball, found him, and brought him aboard to sail with him. Chief Kimball is one of the few enlisted men in the Navy qualified to be officer of the deck on a ship of this class. My duties as a chief involve the process and the training evolution of, in some cases, seniors, most cases, juniors, trying to train somebody to some day that will follow along in my place. My job as a navigator is to keep the ship off the rocks avoid collision and train my people to the extent that professionally they can do the same. Lieutenant Lewis A. Nick Jr., navigator of the cruiser, California. When he was an ensign, Chief Kimball was his instructor in navigation school. Now, together, they get the ship where she needs to go. Everybody who was an officer of the deck learns navigation by watching people do it and by practicing it. Chief Kimball is the man to watch, and he is the man to learn from. The officers, particularly junior officers, are most dependent on chiefs to teach them everything that they can ever learn about technical parts of operating a ship. The things that they learn that make them good officers, they learn from chiefs. Looks pretty good to me. Captain Floyd H. Miller Jr., commanding officer of California. Known by his men as one of the best ship drivers in the Navy, one of his chiefs said, there are two skippers in the Navy I'd sail to the bottom with. This captain is one of them. A function of a chief the way I see it is that he is a technician and he's a middle management leader. He's had lots of years of experience in the Navy, otherwise he wouldn't be a chief. I think that a chief must provide training to his junior officers in particular. And that's where I look back to my first chief in the Navy who took me under his wing. John Tobin insisted that things be done right, he ensured that they were done right, and his men all understood that. And I saw that that worked very well, and I think some of that rubbed off on me. This is executive officer Commander Fred Triggs, a nuclear specialist. He is in charge of the day-to-day administration of the ship. Early in my career, fortunately, I had an exceptionally fine chief electrician's mate as my leading chief, and I well remember the day he sat me down in a repair locker after we secured from General Quarters. Let me tell you how it is. I've never forgotten that. Executive officer depends a great deal on a chief body officer. He expects that chief body officer with his vast experience in the Navy to know basically what has to be done. Very good. The California cuts through the Atlantic. Her twin nuclear reactors provide her unparalleled speed and endurance. Her helmsmen say she is so responsive, she can go from full speed ahead to a dead stop within a distance equal to five times her own length. In the days when the first California sailed, the eyes and the ears of the ship were found in the crow's nest high above the deck. In the new California, the crow's nest is here, deep within the ship, in an area known as the Combat Information Center. This is Senior Chief Sonar Technician Richard P. Lee. With his pethometer and his sonar, he is as familiar with the bottom of the sea as Chief Campbell is familiar with its surface. With this new long-range sonar, we don't really do that much navigation anymore, but as far as sound ranging, in other ways, ASW Warfare, we would go out and get the range and the bearing, just get the target. Primarily with this sonar is all about today's sonar as compared to World War II would be something like comparing a Model T-4 to a Ferrari. Chief? Yeah. We've got a contact over here bearing 335 range 4000. It could be that wreck off Chesapeake Bay. The range of bearing sounds good. Why don't you check with the bridge to make sure? Bridge sonar, we have contact bearing 335 range 4000. Could be the wreck off Chesapeake Bay. Will you verify, please? I got it. Murray informed combat to inform sonar of the contact they hold as a chartered wreck. Aye. Combat bridge informed sonar. If the wreck had turned out to be an enemy submarine, the safety of California would also have been in the hands of this man. Chief Operation Specialist Dudley Locke. Still in his 20s, Chief Locke is among a new breed of Navy chiefs. Those whose unusual technical skills, intelligence and leadership qualities have brought them through the ranks quickly to positions of immense responsibility at an early age. Chief Locke is responsible for the men and systems comprising the offensive and defensive combat readiness of California. His station is a labyrinth of consoles and computers and highly sophisticated electronic systems. But none of this technology can be any more effective than the effectiveness of Chief Locke and the 28 men in his division. Basically I'm responsible for the smooth operation and the training of personnel who man the combat information center. Just about everything that happens on board this ship is somehow related to CIC. We have a pretty big breaking point between the petty officer level and the chief petty officer level. In fact, I think you become a hell of a lot smarter overnight. All of a sudden I had just a little more respect and people weren't just running around calling me by my last name, it was chief. And that meant a lot to me. There was a time when the men who first sailed this sea had few rights and were little more than prisoners in the ships they sailed. The world has changed. The Navy has changed. This is a meeting of the Human Relations Council. It meets regularly both in port and at sea. Its proceedings are based on the fact that a ship's crew is a society of free individuals. And as in any society, harmony and group welfare may at times seem to inhibit individual freedom. Chief Lee is the ship's senior enlisted advisor. Through him, every enlisted man on the ship has access to the ear of the captain. You can't treat 500 people like they'll want. Each person is an individual. Being an individual, they've all got their different wants or different needs. We get the people together. If they've got a problem, they'll bring it up to me. When I bring these problems up to the committee, I'm talking directly to the higher echelon, the executive officer, the education services officer, the prime movers in the command. And they're the people that can normally correct 60 to 80 percent of the problems right on the spot. The other 20 percent we work on. This ship was built to be self-sufficient. Being nuclear power, we can go for many years, well over a decade without refueling. We're not tied to the beach in any manner. We're having that as a capability. The Navy looked to other things that would tie us to the beach. And ensured that we would be self-sufficient in that we have an electrical rewind shop where we can rewind essentially any motor that we have on board. We have a large machine shop that we can repair practically any piece of equipment on board. We ran out of beans and bullets. Well, then we'd have a problem. But I don't have to worry about fuel, repair capabilities, or what have you on board. I'd say one of the most self-sufficient cruisers in the Navy. Flight quarters, flight quarters for personnel transfer. All hands not involved in helicopter operations remain clear. Flight deck areas have to frame 151. All topside personnel remove hands. Almost all ships in the Navy today have the capability to land and launch some size or type of helicopter. We split up the responsibilities for what has to be done on the flight deck. We have to be able, obviously, to land and launch helicopters safely. We have to be able to refuel them and maintain them. We have to be prepared in the event of emergency landing or fire. Fuel for a jet aircraft in this helicopter is a jet aircraft. It's extremely critical as far as purity and lack of water suspended in it. Daily the fuel chief tests the fuel and then again he samples it just before it's put into the aircraft. And they are putting their lives in that flying airplane in the hands of that Chief Petty Officer who says it's good, comfortable. Chief Fieber is an exceptional Chief Petty Officer and one that inspects your altitude. But a helicopter is an airplane and it's a funny airplane. It's not natural for it to fly and it's landing on a small deck, often one that's pitching and rolling, sometimes one that's wet. The operation of any aircraft is a hazardous operation. One of the most hazardous things that we do, like that operations landing and launching are under control of the landing signal enlisted LSE. Fueling is under the responsibility of the fuel chief, firefighting, crash crew, and the responsibility of a damaged control chief. So we've split it up. Each of them runs his own organization. He's responsible for the training efforts that we do. Each of them runs his own organization. He's responsible for the training effort. He's responsible for it being at flight quarters on time and responsible for what it does or can be called upon to do. It's because the Chiefs and the First Class Petty Officers are taking charge of their area of responsibility and making it work. All I have to do is be back there and watch. That's a camp. Hold on to flight deck, Bruce. There are conflicts between a seagoing career and a family. Most of them are essentially the fact that you're gone for a good portion of every year. I don't like him being away so much, but that's what he wants out of life. He wants a Navy career, and he was in the Navy when I married him. During the time that you are home, you have to really just live a year in those maybe six months that you are there. Before Dudley has to go to sea, he tries to get everything done that needs to be. I think for her that it's a very difficult thing, especially knowing that she has to run the home, bring up Tiffany and all the other little lids and ends that I normally do when I'm here, and she has to do when I'm gone. The day the ship pulls in is really exciting. I have butterflies in my stomach. Tiffany's all excited, and I can't sleep the night before he comes home. It's always excitement, really. I believe my family and friends have a pretty good understanding of the rank of Chief and what it means to be a Chief Petty Officer. When Dudley made Chief, it just seemed like our whole lives changed, because he had worked so hard for it, and just seemed like it was so much more exciting. He seemed so more enthused, and I seemed to get more interested in the Navy since he has made Chief. You lose track of time, bring it out at sea. When you keep busy, the time goes on pretty good clip. But you do think of the family a lot. You just wonder what's going on. When we got married, I knew he was going to be a Korean man. There was no doubt in his mind at that time. As fast as when he leaves, the feeling has never changed. It's still a big let down, but the kids keep me busy, so time goes by a lot faster. I keep occupied, I keep my time occupied, so it doesn't seem quite so long in between the time he leaves and the time he comes back home. When we know he's coming back in, the kids have a big thing, we have a big countdown. When it gets to 10, the baby holds up 10 fingers and so on, and it's a big deal. And then the day he's supposed to be coming home, you just can't live in my house. Just about anything, they'll bring up in the history books about this place, that place, or anything along that line. The older children especially can say, hey, I've been there. They live where they have lived what other kids have to study. When he made chief, proud of him, I really was. It was a big deal. As far as I was concerned, he was happy about it. Prestige-wise, if that's the right word. Yeah, really proud of him. I really was, at that time. Still am. It is no accident that brought California to these waters. She is a fighting ship. Her mission is to be ready in a world that demands readiness. And so, as a fighting ship, she has sailed to a test area in the high seas to see what kind of punch she has. I've tracked 807 bearing 355 range, 19 miles. On tail, SWIC, warning red, weapons free. Tail, right? Warning red, weapons free. Captain, area's clear. Track 807 bearing 354 range, 18 miles. SWIC tail, birds free. T-minus one in county. Launch area is clear, launching system is right at fire. Track 807 bearing 357, range 16 miles. 07 bearing 353, range 15 miles. T-minus 30 in county. TM is internal. Track 807 bearing 356, range 13 miles. T-minus 10, 9, 7, 4, 3, 2, 1, fire. 07 bearing 348, range 10 miles. Mark India, target pass through the gate. Looks like a success. Track 8007 bearing 351, range 6 miles. Mark Delta. Alright, good shot. One major phase of California's mission has been successfully completed. Before her crew wrestles with the challenges of another phase, California anchors at St. Thomas in the Virgin Islands. Liberty's released from tension. When you're on deployment, you're isolated. You're on a ship doing a certain thing. And when you go into a port, then you want us cut loose.  When you're over in a foreign country, you are representing the United States. And it's nice if you go over there to a person who's never seen an American and if you're leaving with a good impression of them, you're leaving with a good impression of the States. One of the reasons that I joined the Navy was I wanted to see the world. I thought it would be very interesting to see peoples of other cultures and lifestyles and compare them to our own in the United States. I ate pizza with the Italians and drank beer with the Germans. I really thought it was exciting to be overseas and talk to other people and understand the way that they lived. It's still exciting to me when we go over. I've seen considerably more in the last 15 years than the normal person probably ever seen in their lifetime. I've enjoyed it. Through traveling and going to show in different countries, you more or less educate yourself to things that people spend most of their life trying to read out of textbooks. And if you get to experience firsthand then you can supplement with the textbook and you have a better understanding of people. 310 will carry you left the track and that will just keep easing you over. All that's like and keep turning 25 knots on it. Got a good text chief? Right course 29, 30 knots. Right, coming to course 29, 30 knots. Another phase of California's mission is gunfire support which requires very precise and demanding coordination between the bridge, the chiefs, and their men. Coming, coming, right. If there is a central focus during this exercise, it is the Combat Information Center and on Chief Lock. 200 yards to the open fire point. Good exercise. Time to go. 1,000. 1,000. 1,000. 1,000. 1,000. 1,000. 1,000. 1,000. 1,000. 2,075. 5. 2,000. 3 minutes to open fire. We agree on course and speed. 2,500 yards to open fire point. 2 and 1 half minutes. 1,500. 1,000. 2,100 yards to open fire. Big Mary 26, Charlie. This is Charlie Echo. This is Big Mary 26. Good position. 5,7,2,3,8,5. Course. 1,5,5. Speed, 2,500. This is Big Mary 26. 1,000. 1,000. 1,000. 1,000. 1,000. 1,000. 1,000. Charlie uniform 0,948. Over. Fire mission target. Charlie uniform 0,948. We're in 5,3030. 3,0060. Altitude 9 or 5. Meet direction 2,9 or 5. Degrees true. Troops in open. High explosive fuse, quick main armament. One gun, spotter just over. Troops in open. High explosive use switch. 5,3030. 3,0060. Altitude 9 or 5. Meet direction 2,9 or 5. Degrees true. Troops in open. High explosive use switch, quick main armament. One gun, spotter just out. Stand by. 1,000. 1,000. 1,000. 1,000. 1,000. 1,000. 1,000. The chiefs. A company of rather uncommon men. Rugged individuals. Professionals. They say the Navy is changing and so it should. But there is something in the chief that never changes. And that's Navy life at sea. The love of it. The respect of it. The commitment to it. It's some intangible that has been passed from one chief to another to another. Since the days of sail and the first California. This is Captain. Needless to say I am extremely gratified with the performance of the ship in a crew. We achieved a grade of 96.4 in gunfire support exercises and had four successful missile shots. I think that this is the type of performance that our Navy and our nation expect of a ship of this class. Well done to the crew. That's all.