Tag Archives: code
I know people bag on c++ (for many valid reasons) but it still amazes me to learn something new: read only members using const references. It’s even better when a c++ non-fan teaches you about it. Thanks Nico!
class Test
{
public:
Test() : readOnlyVersion(m_writableVersion)
{}
const SomeType & readOnlyVersion;
private:
SomeType m_writableVersion;
};
Never having a need, I had always filtered out reference data members – I just categorized them with static members and their special initialization. Now that I see a use case, I’m basking in the “Ah that makes total sense” moment.
Got a new wordpress plugin from http://alexgorbatchev.com/SyntaxHighlighter/, let’s see how it works, by drawing on a recent facepalm bug that existed for many years in the codebase..
#ifdef linux
struct SomePThreadContainer {
pthread_mutex_t mutex;
int other_data[32];
};
#define ODD_DATA_SIZE sizeof(SomePThreadContainer)
#else
#define ODD_DATA_SIZE sizeof(HANDLE)
#endif
class OddWrapper {
byte m_oddAbsraction[ODD_DATA_SIZE];
public:
void DoStuff();
};
class OddContainer {
OddWrapper oddOne;
bool b1;
OddWrapper oddTwo;
public:
void VerifyOneWorksOnUse();
void VerifyTwoFailsOnUse(); // but will work if b1 is changed from a bool to an int
};
Many bothans were NEEDLESSLY lost to bring you this bug. 🙂
