Symbian C++ 三宗罪
1. 两段构造
依赖于CBase的两段构造,完全可以用如下代码取代:
#define NEWLD(ClassExp) new(true, false) ClassExp; CleanupStack::Pop(1);
inline TAny * operator new(TUint aSize, bool, bool)
{
ASSERT(aSize != 0);
TAny * pTmp = User::AllocLC(aSize);
return pTmp;
}
inline TAny * operator new[](TUint aSize, bool, bool)
{
ASSERT(aSize != 0);
TAny * pTmp = User::AllocLC(aSize);
return pTmp;
}
只要每个类的头文件包含以上的代码,就可以不依赖继承CBase类的两段构造。
2. 异常退出
以下代码使用了Symbian的异常退出语句,来模拟标准的C++异常处理,
#define TRY(exp) \
{ \
bool _ep_Handle = false; \
TRAPD(_ep_Exception, {exp});
#define CATCH_BEGIN \
switch(_ep_Exception) \
{ \
case KErrNone: \
_ep_Handle = true; \
break;
#define CASE(err) \
case err: \
_ep_Handle = true; \
#define DEFAULT \
default: \
_ep_Handle = true;
#define CATCH_END \
} \
if (!_ep_Handle) \
{ \
User::Leave(_ep_Exception); \
} \
}
#define THROW(err) \
User::Leave(err)
#define THROW_DEFAULT \
User::Leave(_ep_Exception)
难道编写简单、容易移植的代码就那么难么?
3. CActive 继承于 CBase
难道就不能增加一个同时继承于 CBase 和 CActive 的 CBaseActive 类么?
非得让CActive继承于 CBase类么?
干净的接口难道就不应该存在么 ?
非要限制CActiveScheduler能够处理活动对象类型为CBase么?
刚开始看Symbian C++,感觉非常的不爽,真心希望Symbian在下一版的平台代码上能够稍微改进一下。