C++
C++ is a very powerful and complex language and inherits all the good and bad of C. It is often used in graphics development, so we will be using it. You will need to learn C++ on your own, but get help if you can't figure something out. Some important points:
-
Classes declared with the
class
keyword. Note the semicolon!class MyTestClass { };
-
Encapsulation is similar to Java:
class MyTestClass { private: ... public: ... };
-
Self reference through pointer to 'this':
class MyTestClass { private: int a; public: MyTestClass() { this->a = 5; } };
-
Inheritance looks like this:
class MyTestClass : public OtherClass { private: ... public: ... };
-
Method overrides for polymorphism require the 'virtual' keyword on parent and child:
class OtherClass { public: virtual int getFive() { return 5; } }; class MyTestClass : public OtherClass { public: virtual int getFive() { return 6; } };
- Supports references with & symbol
-
Generic programming by metaprogramming
template <int dimension> class GenVector { public: static const int dim = dimension; float c[dimension]; GenVector() { for(int i=0; i<dimension; i++) c[i] = 0; } } GenVector<3> threeVec; GenVector<4> fourVec;
-
Often comes with a Standard Template Library of algorithms and collections (we will use this)
#include <vector> std::vector<int> integers; for(int i=0; i<10; i++) integers.push_back( i ); for(int i=0; i<integers.size(); i++) printf("%d ", integers[i]);
- Objects can have constructors and destructors