×
Namespaces

Variants
Actions

Static class in Symbian

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: savaj (07 Mar 2009)
Last edited: hamishwillee (18 Sep 2012)
Reviewer Approved    Thumbs up icon sm.jpg

Contents

What is static class??

Static classes are used to create functions that can be accessed without creating an instance of the class. Static classes can be used when there is no data or behavior in the class that depends on object identity. It is not possible to create instances of a static class.

How to create static class in Symbian?

There is no need to prefix the word "static" to class declaration. just declare a normal class with all functions will be prefixed by word static. You do not need to declare/implement constructor/destructor as they do not have object.

Header file.

// 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;
};

Implementation file.

//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.
}

How to use static class?

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 18 September 2012, at 08:59.
41 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.

×