Game programming week 3 – Classes, classes, classes
|
This week in game programming, we’ve been going through classes a lot. A class is a data structure that apart from variables, also can contain functions. Therefore, a class is often used to store a lot of functions in, so they can be used again within the program without having to rewrite them. A class is created in a header-file, and then called to when it’s used in the ”int main” function call. We also went through class inheritance, which means that you can let a class inherit everything from a class and also add new variables that won’t affect the class inherited from. If a class is thought to be inherited later on, it’s wiser to use the member ”protected” when you have variables in a class that you don’t want other people to mess with. This is because ”protected” makes the variable able to be used in every class that inherits from the first class, while ”private” would make a variable exclusive only to the first class made. In a class, every member added in there is automatically turned into ”private”, therefore, declaring that your variables and functions are ”public” is essential. We also had a seminar this friday where we had to present solutions to excersises in front of the class. This was my solution to the following exercise: Write a program that converts C to F or vice versa. Ask the user on which conversion to make. When the user types ‘q’, quit the program otherwise repeat.
|

