计算机 信息系统 哪四大分类
php 中如何得到一个对象的类型
得到一个对象的类型,使用gettype()函数:
《?phpecho gettype(1); // 输出integerecho gettype(array()); // 输出array
得到一个对象是哪个类的实例,使用get_class()函数:
《?php$o = new stdClass();echo get_class(); // 输出stdClass
得到一个类或对象的方法和属性,要使用反射:
《?phpclass MyClass { public $var; public function foo() {}}$ref = new ReflectionClass(’MyClass’);$ref-》getProperties(); // 会返回一组对象,用法参考PHP手册$ref-》getMethods(); // 会返回一组对象,用法参考PHP手册$obj = new MyClass();$ref = new ReflectionObject($obj);$ref-》getProperties();$ref-》getMethods();
句柄类的句柄类例子
#include 《iostream》using namespace std;//-----------------------------------------class Point{private: int xval,yval;public: Point():xval(0),yval(0) {} Point(int x,int y):xval(x),yval(y) {} int x()const { return xval; } int y()const { return yval; } Point& x(int xv) { xval=xv; return *this; } Point& y(int yv) { yval=yv; return *this; }};//------------------------------------------------------class UseCount{private: int* p; UseCount& operator=(const UseCount&);public: UseCount(); UseCount(const UseCount&); ~UseCount(); bool only(); bool reattach(const UseCount&); bool make_only();};UseCount::UseCount():p(new int(1)) {}UseCount::UseCount(const UseCount&u):p(u.p){ ++*p;}UseCount::~UseCount(){ if (--*p==0) { delete p; }}bool UseCount::only(){ return *p==1;}bool UseCount::reattach(const UseCount& u){ ++*u.p; if (--*p==0) { delete p; p=u.p; return true; } p=u.p; return false;}bool UseCount::make_only(){ if (*p==1)return false; --*p; p=new int(1); return true;}//-------------------------------------------class Handle{private: Point* p; UseCount u;public: Handle(); Handle(int,int); Handle(const Point&); Handle(const Handle&); Handle& operator =(const Handle&); ~Handle(); int x()const; Handle&x(int); int y()const; Handle&y(int);};Handle::Handle():p(new Point) {}Handle::Handle(int x,int y):p(new Point(x,y)) {}Handle::Handle(const Point&p0):p(new Point(p0)) {}Handle::Handle(const Handle&h):u(h.u),p(h.p) {}Handle::~Handle(){ if (u.only()) { delete p; }}Handle& Handle::operator=(const Handle &h){ if (u.reattach(h.u))delete p; p=h.p; return *this;}int Handle::x()const{ return p-》x();}int Handle::y()const{ return p-》y();}Handle& Handle::x(int x0){ if (u.make_only())p=new Point(*p); p-》x(x0); return *this;}Handle& Handle::y(int y0){ if (u.make_only())p=new Point(*p); { p-》y(y0); return *this; }}//---------------------------------------------------int main(){ Handle h(3,4); Handle h2 = h; h2.x(5); int n = h.x(); cout《《n《《endl; return 0;}-分类信息系统