/* try.cpp - for trying out some language features.... * scons will create the binary bin/try * */ // 8/07 - how to control NOBUG?? // execute with NOBUG_LOG='ttt:TRACE' bin/try // 1/08 - working out a static initialisation problem for Visitor (Tag creation) #include #include using std::string; using std::cout; NOBUG_CPP_DEFINE_FLAG(test); template class Tag; template class TagTypeRef { public: static Tag tag; }; template class Tag { size_t tagID; static size_t lastRegisteredID; public: Tag(size_t tt=0) : tagID(tt) {} operator size_t() const { return tagID; } template static Tag& get (TOOLImpl* const concreteTool=0) { INFO (test,"getTag"); Tag& t = TagTypeRef::tag; if (!t) t.tagID = ++Tag::lastRegisteredID; return t; } }; /** storage for the Tag registry for each concrete tool */ template Tag TagTypeRef ::tag (0); template size_t Tag::lastRegisteredID (0); class TT { }; class TI : public TT { }; class TII : public TT { }; int main (int argc, char* argv[]) { NOBUG_INIT; size_t xxx = Tag::get(); cout << "created Tag=" << xxx <<"\n"; cout << "created Tag=" << Tag::get () <<"\n"; return 0; }