摘要:
download demo project - 27.4 kb
download source - 5.09 kb
introduction
asp.net provides us with many easy ways to build our web system, especially the code-behind technique which amazingly allows a separation of layout an......
摘要:有些时候需要不让对话框在运行时显示出来,用showwindow的方法会有闪动现象,我认为最好的方法是用create.具体过程如下:
假设建立一个vc.net工程gettime,首先在cgettimeapp类中添加一个成员变量:cgettimedlg *dlg;然后在initinstance()中将原来的:
int nresponse = dlg.domodal(); if (nresponse == idok) { // todo: place c......
在C++中侦测内嵌型别的存在(原创)动机(motivation)
template<class t> 【相关文章:
Hibernate:利用配置文件生成数据】
假设一所大学的注册系统提供了一个注册函数: 【扩展阅读:
软件可重用性的一点思考】
{ 【扩展信息:
把Oracle数据库移植到Microso】
void register(t person)
register(person,typename t::person_tag());
};
而对于注册者有以下几种标识:
struct student_tag{};
struct teacher_tag{};
还有register的几个供内部使用的重载版本:
template<class t> void register(t p,student_tag){...} //注册学生
template<class t> void register(t p,teacher_tag){...} //注册教师
并规定学生类一定要在内部typedef student_tag person_tag ;教师类typedef teacher_tag person_tag ;这样,当传给起初的那个register的对象为学生类对象时,typename t::person_tag()其实构造了一个student_tag对象,从而激发函数重载,调用register内部版本的template<class t> void register(t p,student_tag);版本。其他情况亦均有对应。这是泛型编程里的常用手法,stl里屡见不鲜。
问题是,现在学校里假如不止学生教师,还有工人,警卫等其它人员。如果他们不会在类内部typedef任何东西,则register需要一种机制以确定t内部是否typedef了某个标识符(例如person_tag)。如果没有,就默认处理。如果有,则再进行更详细的分类。
实现(implementation)
这个问题可能有两个实现途径。
第一,利用函数重载,具体如下:
typedef char (&yes_type)[1]; //sizeof(yes_type)==1
typedef char (&no_type)[2]; //sizeof(no_type)==2
以上的两个typedef用于识别不同的重载函数。char (&)[1]表示对char[1]数组的引用,所以sizeof(char(&)[1])==sizeof(char[1])==1;注意围绕&符号的一对圆括号,它们是必要的,如果没有将会导致编译错误,正如char* [1]将被解析为char*的数组,char& [1]将被解析为引用的数组,而后者是非法的。将&用圆括号包围则改变了运算符的结合优先序,这将被解析为对char[1]数组的引用。
template<class t>
struct does_sometypedef_exists
{
template<class u>
static yes_type check(u,typename u::key_type* =0); //请注意* 与=之间的空格,那是必要的,否则
//编译器会将它解析为operator*=操作符
static no_type check(...);
static t t; //声明
static const bool value=sizeof(check(t))==sizeof(yes_type);...
下一页 摘要:如何取得三个键盘提示灯当前状态
用api 函数 getkeyboardstate,例如:unsigned char kbuf[256];getkeyboardstate(kbuf);
if(kbuf[vk_capital]&1)getdlgitem(id_caps_lock_key)->setwindowtext("on");else getdlgitem(id_caps_lock_key)->setwindow......