| double max(double first, double second); complex max(complex first, complex second); date max(date first, date second); //..该函数的其它版本 |
| double max(double first, double second) { return first>second? first : second; } complex max(complex first, complex second) { return first>second? first : second; } date max(date first, date second) { return first>second? first : second; } |
| // file max.h #ifndef MAX_INCLUDED #define MAX_INCLUDED template <class T> T max(T t1, T t2) { return (t1 > t2) ? t1 : t2; } #endif |
| int n=10,m=16; int highest = max(n,m); // 产生 int 版本 std::complex<double> c1, c2; //.. 给 c1,c2 赋值 std::complex<double> higher=max(c1,c2); // complex 版本 |
| template <class T> T max(const T& t1, const T& t2) { return (t1 > t2) ? t1 : t2; } |
| unsigned int htonl (unsigned int hostlong); unsigned short htons (unsigned short hostshort); unsigned int ntohl (unsigned int netlong); unsigned short ntohs (unsigned short netshort); |
| template <class T> T byte_reverse(T val); |
| template <class T> T byte_reverse(T val) { // 将 val 作为字节流 unsigned char *p=reinterpret_cast<unsigned char*> (&val); std::reverse(p, p+sizeof(val)); return val; } |
| int main() { int n=1; short k=1; __int64 j=2, i; int m=byte_reverse(n);// reverse int int z=byte_reverse(k);// reverse short k=byte_reverse(k); // un-reverse k i=byte_reverse(j); // reverse __int64 } |
| C/C++学习参考资料 |
| Visual C++开发工具与调试技巧集合 |
| VC简单开发实例 |
| 远程控制——远程关机的实现 |
| 用carray解决多维动态数组问题 |
| 使用C++和XML建立智能文档(一) |
| 使用C++和XML建立智能文档(二) |
| 使用C++和XML建立智能文档(三) |
| PE文件格式详解(4) |
| PE文件格式详解(1) |
| C++学习:在C++中创建持久对象 |
| C++数据结构学习:递归(3.1) |