Warrior Tang (tangaroa) wrote,
Warrior Tang

Note dump: Scraps and debris, part 2

Since the ACM Programming Competition allows schools to send multiple teams that can earn different scores, I wrote a script to produce "average" scores per school. SSU usually places in the middle of all of the schools, but both of SSU's teams got crushed in 2010, giving the school an overall second-to-last place finish by my formula. Did everyone spend the night before partying or something?

Could mutexes be a language feature? Imagine a language where "mutex" is a keyword and mutex name { BLOCK } would cause the compiler/interpreter to add whatever code is necessary to create a mutex with that name over that block of code.

Some fun C++ errors:

xReader5.cc: In member function `bool nodeReaderContext<cxEnumType>::operator==(const nodeReaderContext<cxEnumType>&) [with cxEnumType = e_nodeReaderContext]':
xReader5.cc:33: error: passing `const nodeReaderContext<e_nodeReaderContext>' as `this' argument of `const cxEnumType nodeReaderContext<cxEnumType>::getValue() [with cxEnumType = e_nodeReaderContext]' discards qualifiers

The getValue() function doesn't dirty any value. It is simple enough that I defined it in the header:

virtual inline cxEnumType getValue() { return value; }

The solution, by way of some more IBM documentation, is to add a "const" in a place I've never seen a const placed before:

virtual inline cxEnumType getValue() const { return value; }

This turns the "this" pointer into a const for this function.

Now for the next compiler error. I have the .cc file define a cx_Scanning class derived from class nodeReaderContext that calls its parent's constructor.

class cx_Scanning : nodeReaderContext{ cx_Scanning() : nodeReaderContext(V_SCANNING){ ; } string toStr(){ return "Scanning"; } };

This produces the error message:

xReader5.cc: In constructor `cx_Scanning::cx_Scanning()':
xReader5.cc:41: error: class `cx_Scanning' does not have any field named `nodeReaderContext'

nodeReaderContext is the name of the parent and the parent's constructor, not a field or member of either object. The solution to this one comes from blind experiment. It turns out that I had to add a template to the part that calls the parent's constructor:

cx_Scanning() : nodeReaderContext<cxType>(V_SCANNING){ ; }

That solves whatever problem the compiler was having.

  • Post a new comment


    default userpic

    Your IP address will be recorded