10 2012 档案
摘要:C++中,operator 关键字的作用有两点:1.操作符重载。2.对象类型的隐式转换。这两种作用都比较好理解。下面主要介绍,利用“作用2”在解决 “Testing Smart Pointers for Nullness” 。为了实现 智能指针的 ptn == 0 || ptn!=0) || ptn || !ptn, 判断,需要将智能指针隐式转换成bool.总结下,常见有4种实现方法:operator bool() {...}operator const void*() {...}typedef T* (CLASS::*CLASSMEMFUNPT) (); operator CLASSMEM.
阅读全文
摘要:C++编程思想里的一个例子。先看代码:handle.hpp#ifndef HANDLE_H_
#define HANDLE_H_ class handle { struct cheshire; //这里通知编译器cheshire是个结构体,结构体的定义编辑器将在cpp中找到 cheshire* smile; public: void initialize(); void cleanup(); int read(); void change(int);
}; #endif // HANDLE_H_handle.cpp#include <io...
阅读全文
摘要:#include<stdio.h> int div(const int x,const int y){ return x/y;
} //位移,效率高
int myDiv(const int x,const int y){ int tmpY = y; int dividend = x; int result = 0; while( dividend >= y ){ int lsCount = 0; //left shift counter while( tmpY <= (dividend >> 1) ){ ...
阅读全文
摘要:很久不写正则表达式了,网上看到个面试题关于提取<a href=‘提取我’/>, 各种乱七八糟的解法。正确的,应该是这样吧:import java.util.regex.Matcher;
import java.util.regex.Pattern; public class TestReg { static void ParseHref(String str) { System.out.println(str); System.out.println("开始匹配"); Pattern pattern = Pattern.compile("(<a(
阅读全文

浙公网安备 33010602011771号