Skip to content
Permalink
Browse files
Updated picture links
  • Loading branch information
ab8809 committed Dec 13, 2019
1 parent 086684c commit 56c760870968e96f678cb0b7449f15ef0ec76d3f
Showing 1 changed file with 18 additions and 18 deletions.
@@ -1,18 +1,18 @@
# Session 2 - Using Classes

#### Table of Contents
1. [Why use classes?](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/README.md#why-use-classes)
2. [Creating a class](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/README.md#creating-a-class)
3. [Header and C++ files](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/README.md#header-and-c-files)
4. [Making a basic class](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/README.md#making-a-basic-class)
5. [Using the new class](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/README.md#using-the-new-class)
6. [Creating multiple instances of the class](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/README.md#using-the-new-class)
7. [Documentation](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/README.md#documentation)
8. [Homework](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/README.md#homework)
1. [Why use classes?](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/README.md#why-use-classes)
2. [Creating a class](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/README.md#creating-a-class)
3. [Header and C++ files](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/README.md#header-and-c-files)
4. [Making a basic class](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/README.md#making-a-basic-class)
5. [Using the new class](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/README.md#using-the-new-class)
6. [Creating multiple instances of the class](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/README.md#using-the-new-class)
7. [Documentation](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/README.md#documentation)
8. [Homework](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/README.md#homework)

Last session, we created a GitHub repository in the 217CR organization and added our base Visual Studio project to it.

> You haven't done all of those things? Go back to Week 1 and complete that tutorial!
> You haven't done all of those things? Go back to Session 1 and complete that tutorial!
For this week's session, we will be setting up a basic class for practice for your coursework and looking into a student's worst nightmare - documentation of their code.

@@ -75,7 +75,7 @@ There are 3 ways you can create a class.

> All three of these ways work the same and it is more down to personal preference. I would suggest you try all three to see which one you like the most.
![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/Readme%20Pictures/Class%20creation.png)
![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/Readme%20Pictures/Class%20creation.png)

For all 3 methods, you can either access them via _"Project"_ in the top menu or by right clicking _Source Files_ or _Header Files_ in the "Solution Explorer".

@@ -85,11 +85,11 @@ For the _"Class Wizard"_, click on _"Add Class..."_. (This will open up the _"Ad

For the _"Add Class"_ method, type in the _Class Name_ section and it will automatically fill out the _.h file_ and _.c++ file_ names. Click _"OK"_ when you have a sensible name.

![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/Readme%20Pictures/Add%20Class.PNG)
![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/Readme%20Pictures/Add%20Class.PNG)

Whatever method you used, you should have a header file (_.h_) and a C++ file (_.cpp_) file now present in the "Solution Explorer". Normally, the header file automatically opens so you can work on it straight away.

![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/Readme%20Pictures/Class%20Created.png)
![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/Readme%20Pictures/Class%20Created.png)

> What is _#pragma once_ ? That's part of this session's homework!
@@ -146,9 +146,9 @@ Now, we could type the needed parts out manually... But, as programmers, we are

Hover your mouse over each part of the code with a squiggle and click on the screwdriver. Choose _"Create definition of ... in Cube.cpp"_ for all three of the needed areas.

![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/Readme%20Pictures/No%20definition.png)
![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/Readme%20Pictures/No%20definition.png)

![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/Readme%20Pictures/Added%20functions.PNG)
![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/Readme%20Pictures/Added%20functions.PNG)

Make sure your C++ file looks like this.

@@ -182,13 +182,13 @@ void Cube::Draw()
```
Once this is added, you might notice that this is underlined with red squiggly lines. Hovering your mouse over any of these lines should give you a pop up window saying that _X is not defined_.

![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/Readme%20Pictures/OpenGL%20red%20functions.PNG)
![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/Readme%20Pictures/OpenGL%20red%20functions.PNG)

If we try to now run our code, we will get a number of errors messages as well as pop up window saying **There were build errors.** Click the _"No"_ option to go back to Visual Studio.

The "Error List" at the bottom of Visual Studio contains all the errors that stopped the project from compiling and running. Warnings do not stop it from compiling and running but are shown to us as a "You might want to look at this" type of message.

![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/Readme%20Pictures/Error%20List.PNG)
![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/Readme%20Pictures/Error%20List.PNG)

> When reading errors, start at the top of the list and read that first. **It might be that all the errors exist only because of this one.** This means that by fixing the top one, it may also fix all the others too.
@@ -261,7 +261,7 @@ Hopefully, it is obvious this happens in the _drawScene_ function, where the res
Running the project now will give us a red cube in the middle of the scene. Yay!
![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/Readme%20Pictures/red%20cube.PNG)
![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/Readme%20Pictures/red%20cube.PNG)
## Creating multiple instances of the class
@@ -386,7 +386,7 @@ cube3 | (3, 0, 1)
Once you have, run the project and check your scene to the example below.
![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Week%202/Readme%20Pictures/3%20cubes.PNG)
![](https://github.coventry.ac.uk/217CR-1920JANMAY/Teaching-Material/blob/master/Session%202/Readme%20Pictures/3%20cubes.PNG)
## Documentation

0 comments on commit 56c7608

Please sign in to comment.