$ cd ~/cs35/labs/ $ git clone <link you got from github> ./lab02You should also update your examples repository by going in your examples directory and pulling the updated version of the repository
$ cd ~/cs35/examples/ $ git pull
So far, we have always compiled our projects using the clang compiler directly, even when the project consisted of multiple files. This becomes rather inefficient for large projects, so today, we introduce a much more efficient way of compiling projects: Makefiles.
Go to the ~/cs35/examples/week02/fromClass/dog folder and execute the command ls to get the list of files. Just as for Lab01, there are three .cpp files here that must be compiled together. We could compile them using
$ clang++ -std=c++11 -o dog dog.cpp poodle.cpp main.cppBut instead, this time, we will use a Makefile. Feel free to open the Makefile with your favorite text editor to see what is there, but we will not explain it this time. For now, you only need to know that you can compile everything in the folder by executing the command
$ makeand you can clean up the folder by erasing all the .o files and the executable file dog by executing the command
$ make clean
Let's look at some examples in the examples/week02/fromClass/dog/ folder. There are also examples in the examples/week02/fromClass/shape/ folder.
Polymorphism requires us to define some methods as virtual or pure virtual. The virtual keyword is added to the front of a method declaration in the base class to indicate it may be implemented differently in a derived class. Appending =0; to the method declaration makes a method pure virtual. These methods are not implemented at all in the base class and must be implemented in the derived class.
In our examples, Poodle and Dalmatian are derived classes of the base Dog class. Each of these derived classes, declare the pure virtual methods of the base class as normal methods. To indicate these classes inherit from the Dog base class we use the following class definition syntax:
class Poodle : public Dog { /* body */ };In main.cpp we show how to use polymorphism to get Dog pointers to act like Poodle and Dalmatian.
You will need to use something similar to parse your input files for lab02.
You should get in the habit of running git pull before starting your edits to make sure you have the latest copy. When are temporarily done with your edits, add, commit, push so your partner can know that you've made changes. In general, you and your partner should be working on the lab together, but it is important that each of you have access to the latest version of the code.
In the event of concurrent edits, you may encounter your first merge conflict. Do not panic. Instead, please carefully read the merge conflict guide for details on how to resolve conflicts and merge successfully. Do not blindly add, commit, and push a file that has a merge conflict as you will mostly break your code, and your partners code.