Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Symbian中的静态类

From Wiki
Jump to: navigation, search
Article Metadata

文章
翻译:
hoolee
最后由 hamishwillee 在 22 Dec 2011 编辑


Contents

什么是静态类?

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

如何在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.
This page was last modified on 22 December 2011, at 05:00.
132 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×