windows.h错误分析以及类模板的使…

来源:互联网 发布:如何隐藏域名信息 编辑:程序博客网 时间:2024/06/09 18:33
// TestTemplate.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <iostream>//包含输入输出头文件
using namespace std;

template //定义模板
const T min1(T &t1,T&t2) 
return t1>t2?t2:t1; //返回较小值

template //定义模板
const T max1(T &t1,T&t2) 
return t1>t2?t1:t2; //返回较大值
}

int _tmain(int argc, _TCHAR* argv[])
{
int a,b; //定义整型变量
int mn,mx;
cout<<"Please input 2numbers:"<<endl;
cin>>a;
cin>>b; //接收用户输入
mn = min1(a,b); //调用函数
cout<<"The Min is:"<<mn<<endl;
mx = max1(a,b); //调用函数
cout<<"The Max is:"<<mx<<endl;
Sleep(3000);
return 0;
}

很有时候由于添加windows.h导致原先没有错误的代码出现报错现象,这是由于自定义的函数中有与windows.h中的函数冲突,所以应该重新命名自定义的宏或者函数名。注意:以后命名函数时尽量使用一些不会被系统使用的函数名。
0 0
原创粉丝点击