// Operator learning
// C++ programming language
// P233
namespace user
{
namespace math
{

struct complex
{
douple re, im;
// 
complex(double r, double i) : re(r), im(i){};
complex &operator+(complex &_cpx);
complex &operator*(complex &_cpx);
}

}

}

complex &user::math::complex::operator+(complex &_cpx){
complex cpx;
cpx.re = this.re + _cpx.re;
cpx.im = this.im + _cpx.im;
return cpx; 
}

complex &user::math::complex::operatro*(complex &_cpx){
complex cpx;
cpx.re = this.re * _cpx.re - this.im * _cpx.im;
cpx.im = this.re * _cpx.im + this.im * _cpx.re;
return cpx;
}

// any other code ?
// find something from Internet
// sample of Operatro overloading
#include <string>
class PlMessageHeader
{
std::string m_ThreadSender;
std::string m_ThreadReceiver;

// return true if the messages are equal, false otherwise
inline bool operator == (const PlMessageHeader &b) const
{
return ( (b.m_ThreadSender == m_ThreadSender) &&
(b.ThreadReceiver == m_ThreadReceiver) );
}

// return true if the message is for name
inline bool isFor (const std::string &name) const
{
return (m_ThreadReceiver == name);
}
// return true if the message is for name
inline bool isFor (const char *name) const
{
// since name type is std::string, 
// it becomes unsafe if name == NULL. 
return (m_ThreadReveiver == name);
}
}

// Operators as member functions
// binary operator as member function
Vector2D Vector2D::operator+(const Vector2D &right) const {...}

// binary operator as non-member function
Vector2D operator+(const Vector2D &left, const Vector2D &right) 
{
//...
Vector2D result;
result.set_x(left.x() + right.x());
result.set_y(left.y() + right.y());

return result;
}

// binary operator as member function with dual arguments
friend Vector2D operator+(const Vector2D &left, const Vector2D &right) {...}

// unary operator as member function
Vector2D Vector2D::operator-() const {...}

// unary operator as mon-member function
Vector2D operator-(const Vector2D &vec){...}

// An example using a 2D vector
friend ostream& operator<<(ostream& out, const Vector2D& vec) // output
{
out << "(" <<vec.x() << ", " << vec.y() << ")";
return out;
}

friend istream& operator>>(istream& in, Vector2D& vec)// input
{
double x, y;
in >> x >>y;
vec.set_x(x);
vec.set_y(y);
return in;
}
 
北京这个地方,就目前来看,没觉得有什么特别的地方,可能是我去的地方少吧。大二的时候想来北京把北京的大学都游历一遍,看来最近要实行这个计划了,可能光是游历也没什么把,要是能写点什么游记之类的,那就不亦乐乎了,哈哈。网上找了一下北京的大学排名,姑且就先按这个顺序来吧。倘若某个大学要是有同学什么的,倒是也可以小聚一下,叙叙旧,聊聊家常什么的也未尝不可。游览顺序暂定如下:
北京大学【曹同学】
清华大学
中国人民大学【王同学】
北京师范大学
北京航空航天大学【研究生】
北京理工大学【郭同学】
中国农业大学
北京科技大学
北京化工大学
北京工业大学
首都医科大学
华北电力
中国石油大学
北京邮电大学【黄同学】
中国地质大学
首都师范大学
北京交通大学【齐同学】
北京外国语大学
北京林业大学
中央民族大学【康同学】
中央财经大学
中国矿业大学【吴同学】
姑且就先这些吧,估计游历这些大学也要耗费一些时间的了,前一阵子本来打算要去游历来着,后来总是找借口说太忙,现在恍然大悟:如果一个事情不抓紧做的话,那估计就没什么机会去做了。事情是一件一件来做的,饭是一口一口的吃的,要想到就去做。
时间问题呢?姑且就定在周末吧,或者周六,或者周日,如果太远的话,可以坐公交或者地铁去,因为骑车子的话,毕竟还是很累的。
定一个大体的时间范围吧:2011-5-20   ----   2011-12-31,可能得优先游历有同学的学校,要不然我担心大家都该毕业了,呵呵~齐同学那里一直没去成,肯定是要亲自去看一看的了。
就这些吧,希望不要白去,要了解这些大学的文化背景,能从细节发掘大学与大学之间的共同点,写点东西,就当是对北京学生生活的一次自娱自乐吧。
永远记住,生活并不和工作矛盾,生活包括了工作、亲情、爱情、友情等等,不要让一些看似重要却又很是轻浮的东西,成为自己的思想的牢笼,要学会突破固有观念和界限,找到一个真实的自我和真实的世界。
拥抱世界吧,哈哈,也让世界拥抱自己吧,哈哈,我来了~
世界,我来了,我真的来了!

姚鑫@2011-5-20 **
 
recv function declaration:
 int recv(SOCKET s, char FAR* buf, int len, int flags);
s[in] : the descriptor that identifies a connected socket.
buf[out] : a pointer to the buffer to receive the incoming data.
len[in] : the length , in bytes, of the buffer pointed to by the buf parameter.
flags[in] : a set of flags that influences the behavior of this function.  

Following is sth about recv() function executing proess in SOCKET:
1. process A calls recv(), recv() function have to wait for DATA IN SEND BUF(发送缓冲)  being transmited by protocol, if there are some errors in transmition about DATA IN SEND BUF, the function return SOCKET_ERROR. 
2. after transmition about DISB,   recv() checks RECV BUF(RB); if socket s[in]'s RB is empty or is receiving data, recv() has to block for a while.
3. after protocol receiving data, recv() copies data in RB to buf[in] (WARNING: data received by protocol may be larger than len[in], length of buf[in], if so, process has to call recv() for several times to copy data in RECV BUF. A IMPORT POINT is that : in fact recv() is just copying data from RB to some buffer, buf[in], and protocol, for example TCP/I&UDP, is the real receiver of data from netwrok part.  )
4. the returning value of recv() is bytes number copied by the function recv(), if an error occurs in "recving", it returns SOCKET_ERROR, and it returns 0 while network is cutted down.  
from: www.wenku.baidu.com
J.Yao 2011-5-14
 
1. definition :  virtual function (paramlist) = 0;
2. if a class A owns one or more virtual functions, A can be caled abstrat base class---ABC.
3. if a class B depried from A( A is abc), and B do not implement the pure virtual function, then class B have to be abc.
4. abstract class can not initialize a instance.
5. if all functions of a class C are pure virtual , the C must be a interface to be used as a base class in class architectures. 
 
抽象基类实现接口一、    创建接口文件.h

#ifndef
_DBSERVER_INCLUDE
#define _DBSERVER_INCLUDE

typedef long HRESULT;

#define DEF_EXPORT _declspec(dllexport)

class IDB
{
   
//Inte***ces
public:
    //Inte***ce for data access
    virtual
HRESULT Read(short nTable,short nRow,LPWSTR lpszData)=0;
    virtual HRESULT
Write(short nTable,short nRow,LPCWSTR lpszData)=0;
    //Inte***ce for
database management
    virtual HRESULT Create(short &nTable,LPCWSTR
lpszName)=0;
    virtual HRESULT Delete(short nTable)=0;
    //Inte***ce
for database information
    virtual HRESULT GetNumTables(short
&nNumTables)=0;
    virtual HRESULT GetTableName(short nTable,LPWSTR
lpszName)=0;
    virtual HRESULT GetNumRows(short nTable,short
&nRows)=0;
    virtual ULONG Release()=0;
};

class
IDBSrvFactory
{
    //Inte***ce
public:
    virtual HRESULT
CreateDB(IDB** ppObject)=0;
    virtual ULONG Release()=0;
};


HRESULT DEF_EXPORT DllGetClassFactoryObject(IDBSrvFactory** ppObject);

#endif

二、    建立对象程序的头文件.h
并进行映射,函数声明顺序和参数跟接口文件一致

#ifndef
_DBSERVERIMP_INCLUDE
#define _DBSERVERIMP_INCLUDE
#include
"..\Inte***ce\DBsrv.h"

typedef long HRESULT;
//#define DEF_EXPORT
_declspec(dllexport)

class CDB:public IDB
{
    //Inte***ces

public:
    //Inte***ce for data access
    HRESULT DEF_EXPORT
Read(short nTable,short nRow,LPWSTR lpszData);
HRESULT DEF_EXPORT Write(short nTable,short nRow,LPCWSTR lpszData);
    //Inte***ce for
database management
    HRESULT DEF_EXPORT Create(short &nTable,LPCWSTR
lpszName);
    HRESULT DEF_EXPORT Delete(short nTable);
    //Inte***ce
for database information
    HRESULT DEF_EXPORT GetNumTables(short
&nNumTables);
    HRESULT DEF_EXPORT GetTableName(short nTable,LPWSTR
lpszName);
    HRESULT DEF_EXPORT GetNumRows(short nTable,short &nRows);

    ULONG DEF_EXPORT Release();
    //Implementation
private:
  
  CPtrArray m_arrTables;//Array of pointers to CStringArray(the "database")
 
   CStringArray m_arrNames;//Array of table names
public:
    ~CDB();

};

class CDBSrvFactory:public IDBSrvFactory
{
   
//Inte***ce
public:
    HRESULT DEF_EXPORT CreateDB(IDB** ppObject);

    ULONG DEF_EXPORT Release();
};

HRESULT DEF_EXPORT
DllGetClassFactoryObject(CDBSrvFactory** ppObject);
#endif

三、   
建立对象的实现文件
参数保持一致

HRESULT CDBSrvFactory::CreateDB(IDB** ppObject)

{
    *ppObject=(IDB*)new CDB;
    return NO_ERROR;
}

HRESULT DEF_EXPORT DllGetClassFactoryObject(IDBSrvFactory** ppObject)
{

    *ppObject=(IDBSrvFactory*)new CDBSrvFactory;
    return NO_ERROR;

}
from:
http://www.cppblog.com/kenbardy/archive/2006/03/14/4146.html(苍羽的学习库)
 
任何颜色都有红、绿、蓝三原色组成,假如原来某点的颜色为RGB(R,G,B),那么,我们可以通过下面几种方法,将其转换为灰度:
1.浮点算法:Gray=R*0.3+G*0.59+B*0.11
2.整数方法:Gray=(R*30+G*59+B*11)/100
3.移位方法:Gray =(R*28+G*151+B*77)>>8;
4.平均值法:Gray=(R+G+B)/3;
5.仅取绿色:Gray=G;
  通过上述任一种方法求得Gray后,将原来的RGB(R,G,B)中的R,G,B统一用Gray替换,形成新的颜色RGB(Gray,Gray,Gray),用它替换原来的RGB(R,G,B)就是灰度图了。


灰度是指黑白图像中点的颜色深度,范围一般从0到255,白色为255 ,黑色为0,故黑白图片也称灰度图像,在医学、图像识别领域有很广泛的用途。
"灰度“代表DPI的值,DPI的意思是每平方英寸有多少象素点,象素点越大,图象的精确
度越大,同时文件的尺寸也越大,当然也不是DPI越大就越好,具体情况具体分析
From:
http://www.cnblogs.com/tyut8518/archive/2008/03/25/1121323.html
 
1.define mouse click message event
    case WM_LBUTTONDOWN: // WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBCLICK
                                        break;
2.catch cursor position
  int x_pos, y_pos;
  x_pos = LOWORD(lParam);
  y_pos = HIWORD(lParam);
3. print mouse cursor position by messagebox()
TCHAR dst[20];
wsprintf(dst, TEXT("(%d, %d)"), x_pos, y_pos);
messageBox(NULL, dst, L"Message", MB_OK);

JUST LIKE THIS!
J.Y