February 04, 2014

Polar graphs - Part 5

Refactoring my code was actually the most frustrating part of this project so far.. I'm used to being able to quickly create files in C# and having the IDE take care of all the linking for me.  Before, I'd vaguely heard of header and source files in C++ but never had to deal with them.. Well, now I have.  Such a freaking headache but I've got a lot of my files finally separated.  My goal is to only have OpenGL related functions in my main.cpp, it's almost getting there.

Here are all of my files:

Main.cpp

constants.h

Parameters.h

Equations.h

Equations.cpp

ColorTriple.h

ColorTriple.cpp

ColorMap.h

ColorMap.cpp

Parser.h

Parser.cpp

Some things I learned along the way:
- Never put using statements in your header files
- It's okay to put #include though
- If you have a single variable in your header file, put extern in front of it (to indicate it's declared elsewhere) and in the .cpp file that's where you declare it (and you don't use extern there).  This caused me a lot of trouble
- Map does not keep ordering.  I guess I just assumed it did.  So I was surprised when my colors all came out looking different
- Use #pragma once in header files to make life easier.  I don't know how guards work as a result
- printf("%s") for strings doesn't work, because %s only works for char*.  Use s.c_str() instead.