Like I mentioned in my previous post, for the last months I had to change my programming language from C# to C++. To show you some of the things that surprised me in the process, I will write a short series of blog posts to emphasize the scenarios and the issues.
The code samples show a simple project that manages cache entries. Several cache entries can exist in a cache session, and cache sessions are managed by a cache manager. The project was created with Visual Studio 2010. My Visual Studio 2010 has applied a color scheme from http://studiostyles.info/ to make it more attractive.
Some notes about the coding style I’m using:
// stdafx.h #pragma once #include "targetver.h" #include <map> #include <memory> #include <string> #include <vector> …
Coming from a C# background, I came to appreciate the syntactic sugar that lets you write less code and helps with project readability. One of these features is the syntactic sugar for getter and setter accessors of object properties. Well, nothing is lost in C++: a property can be easily defined using __declspec. You can read more about this in this blog post. The properties look like this (snippet from CacheManager.h):
__declspec(property(get=get_Owner)) std::wstring const & Owner; std::wstring const & get_Owner() const { return pOwner; }
typedef std::map<std::wstring, CacheEntry<std::wstring>> StringCacheEntryMap;
explicit CacheManager(std::wstring const & owner);
void Add(StringCacheEntry const & entry);
In interest of space, the code pasted in the blog entries may be compacted, in which case some of the rules may be abolished.