Symbian中的静态类

什么是静态类?

静态类不用生成类实例即可用来访问其功能函数,当我们不需要成员数据或根据对象变化的行为,就可以使用这样的静态类。

如何在Symbian中生成静态类?

我们不需要描述类时加上static前缀,只要在所有的函数前面加上static前缀即可。你不需要描述和实现构造及析构函数,因为根本不需要对象实体

头文件

// MyStatic.h.
/** No Need to derive from CBase as this class will never be instantiated over heap**/
class MyStaticClass
{
public: //all function must be public else no one can able to access it.
static void OpenOtherApplication(const TDesC& aUrl);
static HBufC8* ReadFromFile(RFs& aFs, const TDesC& aRootPath, const TDesC& aFileName);
static TInt StartExe(const TDesC& aUID);
        private:
          /** Make Desctructor Pure Virtual so that the class cannot be instantiated or inherited**/
          virtual ~MyStaticClass()=0;
};

源文件

//MyStatic.cpp implementation
void MyStaticClass::OpenOtherApplication(const TDesC& aAppName)
{
//do your work here.
}
 
HBufC8
* MyStaticClass::ReadFromFile(RFs& aFs, const TDesC& aRootPath, const TDesC& aFileName)
{
//do your work here.
}
TBool MyStaticClass::StartExe(const TDesC& aUID)
{
//do your work here.
}

如何使用静态类?

Include MyStatic.h in your class. then directly use as follows
 
TInt error
= MyStaticClass::StartExe(0xea3e3e10); //no need to create instance here.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值