Operator overloading for user-defined types (part 2)

This lesson contains approximately 27 minutes of video content.

Examples of operator overloading

Activity: Overloading the insertion operator for a user-defined type

Graded Playground Autograder

Activity Prompt:

In this problem, you will overload the insertion operator (operator<<) for Student typed objects. We specify the result of inserting a student object into an output stream as follows:

Name: <student.first_name> <student.last_name>
UIN: <student.uin>

where <student.first_name>, <student.last_name>, and <student.uin> are the values of the inserted student object's first_name, last_name, and uin respectively.

#include <iostream> #include "solution.hpp" #include "student.hpp" int main() { }
#ifndef STUDENT_HPP #define STUDENT_HPP #include <string> struct Student { std::string first_name; std::string last_name; unsigned int uin; }; #endif
#ifndef SOLUTION_HPP #define SOLUTION_HPP #include <iostream> #include "student.hpp" #endif
#include "solution.hpp"