I'm switching servers and this problem popped up. It's a bunch of functors I wrote to work with for_each that generate queries for MySQL. Seems my knowledge of inheritance, or atleast, inheritance when involving templates has deminished and I cannot figure this out. Why is it outputting those errors? All code in pastebin here! http://www.mudbytes.net/index.php?a=past...
I'm switching servers and this problem popped up. It's a bunch of functors I wrote to work with for_each that generate queries for MySQL. Seems my knowledge of inheritance, or atleast, inheritance when involving templates has deminished and I cannot figure this out. Why is it outputting those errors? All code in pastebin here! http://www.mudbytes.net/index.php?a=past...
Short answer:
Put a "this->" in front of every member variable and function from the base class.
Long answer:
C++ lookup rules are a little funky within subclasses which inherit template classes. When you use a template parameter in your inheritance part, all the stuff you inherit from the base class is dependent on the template parameter used. Normally, C++ only performs a non-dependent name lookup, so it only looks for variables that have no dependency upon a template parameter. In your situation, you need to tell the compiler that it needs to lookup the dependent names as well as the non-dependent ones. There are couple of ways of doing this, but the easier for you is putting a this-> in front of everything inherited that you use in the subclass.
Just for future reference, what are the other ways of getting it to work?
This is a bit off the top of my head, so it may need to be tweaked a bit. The first form that comes to mind is:
TemplateBaseClassName<T>::base_class_member
Where T is the template parameter you passed to the base class. Alternatively, you could implant references in your subclass that reference the base class members. While this wouldn't work for functions, this would only need you to initialize the references within the constructor once. Those are the best solutions which I can come up with right now.