Help Clarifying Some Material

I can agree with the previous comment, this lesson went crazy fast and covered alot. I just need some help clarifying a couple things:
a) The reason we use virtual and override is because the function or code can be shared between two or more classes, but each class uses that function or code in a different way? For instance with our worldPos() both classes need a reference to the Character’s screen position in the window, which is why the getter is created for a Vector2 getScreenPos( ) and marked as virtual (and abstract)?

b) Can someone explain again what the point of an ‘initializer list’ is, and why we use one in the Character.cpp class?

c) And final question but sort of unrelated, I notice sometimes that the instructor refers to the header file as the class file, which it is, then other times he will refer to the .cpp file as the class file. Is the term ‘class file’ used interchangeably between the header file and the .cpp file? I’m trying to get terminology down as best I can so I’m not sure what to call the .cpp file now.

1 Like

Hey, @Chasech let me see if I can sum it up:

a) We use overrides because the method is an operation of the base class, but may behave differently in different subtypes of that class. Think VehicleWithDoors, with a method OpenDoor. OpenDoor is an operation of all VehicleWithDoors, but for a Bus, the doors will open differently than a car’s doors open.

b) The point of the initializer list is to initialize member variables of the class to the incoming values from the constructor’s arguments. It’s a convenience, and gets them initialized immediately, instead of waiting on the constructor body where assignments are coded.

c) Kind of? The header file is the class declaration file, where member variables and method prototypes are entered. The class definition file (the .cpp) contains all the code implementing the methods. The instructor is just shortcutting. To be clear, you don’t have to define the methods in a CPP file; you could have them in the .H file, but best practice is to declare the class in a .H file and define the methods of the class in a .CPP file.

Hope that helps.

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms