Debugging Overloaded Functions
This exercise has quite a lot of code, so we'll do a little tour.
We have a
getRolePrivileges function, which takes in a
role, which has overloads so it can either be
user, or just a
user roles have additional privileges like deleting and editing.
0:00 In this exercise, we have quite a lot of code, so let's dive into it. We have a getRolePrivileges function, which takes in a role which can either be admin, user, or just a string. 0:11 Admin here, we've basically got AdminPrivileges that's being returned when you pass in this role here. AdminPrivileges, you can see that on adminPrivileges I get access to sites that the user can delete.
0:23 On userPrivileges, I get access to some other stuff too. We have userPrivileges.sites that the user can edit. AnonymousPrivileges, I just get a list of sites that the user can visit.
0:36 In theory, then, each overload should be being triggered. We've got an admin one here returning the AdminPrivileges, role here returning the UserPrivileges, and role string, so every other role gets the AnonymousPrivileges.
0:50 There are some errors here. We're getting some strange errors in here. We're getting some errors here, too, where you seemingly can't pass in anything that isn't admin or user, and anonymousPrivileges are being assigned to Admin and UserPrivileges.
1:07 Your job here is to work out what's happening, knowing what you know about function overloads and especially the implementation signatures, and let's see how far you can get. Good luck.