C++ references

Assigning reference return value to a variable When assigning a reference return value to a variable, a copy is made. Here is an example: class References { private: std::string name; public: References(const std::string& name) : name(name) { }; virtual ~References() { }; const std::string& getName() const { return name; }; }; References r(“foo”); std::string n […]

Inferred typing

I know that .Net 4 is going to have some pretty cool features around dynamic typing and C++0x is also adding some auto typing features. I was thinking about all of this today and realized that what I really use most of the time is an inferred type. Essentially it would infer a new type […]

C++ sorting with the STL

Since I’m doing a lot of C++ these days and working a lot with the STL, I want to jot down some things I’ve had to painfully recall about sorting: The std::sort function really only works with vector If you want to sort a set of pointers, you’ll need to create a comparator function or […]

Writing a marker interface in C++

Just figured this out and it caused me about 3 hours of pain, so I figured I’d post it in case I need to do it again. class Base { public: virtual ~Base() {}; }; class Derived : public Base { private: set someSet; public: virtual ~Derived() {}; set getSomeSet() { return someSet; }; }; […]

Setting up GoogleTest in VS 2008

I’m not a huge C++ developer nor a VS wizard, so I thought I would write down how I got GoogleTest setup in a C++ project I’m using VS 2008 for. Download it Add it as an existing project to your solution by right clicking on the “Solution ‘your-project’” part of the Solution Explorer Compile […]