2005-现在

31 8 2010 In: 生活

还没找到比你更好的。。。

星光大道

4 8 2010 In: 生活

要是有个人叫jichang。或者叫chuansha

他们出广兰路地铁的时候

肯定有种走星光大道的感觉

因为电梯两盘站了很多人

不停在喊:川沙、川沙、机场机场、 –!

电脑又好了

28 7 2010 In: 生活

换了一块显卡

电脑又可以用了

入殓师

19 7 2010 In: 生活

无聊之中,躺在床上看了这部电影,算是一部好的电影。
最精彩的一段应该是主人公爱上了他的所干的事情。
镜头切换到他在荒野里面拉着提琴、
很唯美、
一个很恐怖、很脏的工作被赋予了一个完美的境界、
值得一看

关于mixin

19 6 2010 In: 生活

mixin是Ruby语言的特点之一

它能够让我们给一个类提供一些额外的方法和属性

在一些特定的地方功能强大。特别在代码重构的时候

举一个cegui里面的例子来说明问题

在一个大的系统中,我们会用到很多很多的单件(singleton)

比如对象工厂,系统控制等,我们需要为这些对象提供一个单件的接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;
 
template<typename T>
class Singleton
{
protected:
	static T* m_psSingleton;
 
public:
	Singleton()
	{
		m_psSingleton = static_cast<t  *>(this);
	}
 
	virtual ~Singleton()
	{
		m_psSingleton = NULL;
	}
 
	static T& GetSingleton(){ return *m_psSingleton; }
	static T* GetSingletonPtr(){ return m_psSingleton; }
};
 
class System : public Singleton<system>
{
public:
	void Print()
	{
		cout << " System " << endl;
	}
};
template<> System* Singleton<system>::m_psSingleton  = NULL;
 
 
void main()
{
	System* pSystem = System::GetSingletonPtr();
	pSystem->Print();
}

上面的代码就是为一些基本的类提供一个简单的接口

另外,我们使用mixin的时候

可以在派生类里面声明基类为友元类

这样类似于singleton这样的基类就可以使用派生类的数据

为其提供一些额外的方法,举一个下面的例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;
 
template<typename T> class Display
{
public:
	void Print()
	{
		cout << ((T*)this)->m_nData << endl;
	}
};
 
struct Object : public Display
{ 
	friend class Display; 
public: 
	Object( int nData ) : m_nData ( nData ){} 
private: 
	int m_nData; 
}; 
void main() 
{ 
	Object cObj(100); 
	cObj.Print(); 
}

上面的代码能够让我们为其对象提供一些额外的方法

这两个例子只是mixin的一些应用,但不是全部

C++通过多重继承和模板实现的mixin还能有很多的变化

能够应用于很多场景

侯捷的几本关于模板的书可以拿来看看

模板能够给我们带来很多新的思维和方法

让程序不再那么枯燥:)

博客介绍

也许我们永远不会在这个团队里面一起做事情了.但是NE这个名字永远都会记在我们心中..


Music