Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » template + convert problem
Re: template + convert problem [message #23160 is a reply to message #23152] Sun, 20 September 2009 11:56 Go to previous messageGo to previous message
Didier is currently offline  Didier
Messages: 736
Registered: November 2008
Location: France
Contributor
Hi sergey,


The only words template declaration accepts are: 'class' (or typename) and 'int', all other notations are false and will not compile.

class : means anything, any variable, constant, ... whatever you wan't
int : means only literal integer numbers (1, 2, 1110, 0x10, ...) : no variables !!

But in you're case try this

template <class TBL ,class ID, class NAME,int CLEARTIME>
struct ConvDict : Convert
{
	virtual Value Format(const Value& q) const {
		if(q.IsNull()) return Null;
		static VectorMap<int, String> dict;
		static Time lastcleartime;
		if(GetSysTime()-lastcleartime > CLEARTIME){
			dict.Clear();
			lastcleartime=GetSysTime();
		}
		int f = dict.Find(int(q));
		if(f >= 0){
			return dict[f];
		} else {
			Sql sql;
			sql * Select(NAME).From(TBL).Where(ID == q);
			String s;
			if(sql.Fetch()) {
				int sid = int(q);
				s = sql[NAME];
				dict.Add(sid, s);
			} else {
				s = "";
			}
			return s;
		}
	}
};




I haven't tried it, but at least the declaration is correct





 
Read Message
Read Message
Read Message
Previous Topic: SAPI example
Next Topic: global Object and static std::map --> Crash
Goto Forum:
  


Current Time: Sun Aug 24 18:02:33 CEST 2025

Total time taken to generate the page: 0.05145 seconds