×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    12

    M classes can't have membership data?

    when we started to study Symbian C++, we were often told that M classes had No member data and No constructor (and no destructor, of course). But I S60 SDK include files, i find some exceptions, like this:

    class MCoeControlObserver
    {
    public:

    virtual void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)=0;
    protected:
    IMPORT_C MCoeControlObserver();

    private:
    IMPORT_C virtual void MCoeControlObserver_Reserved1();
    IMPORT_C virtual void MCoeControlObserver_Reserved2();

    private:
    TInt iMCoeControlObserver_Reserved1;
    };

    We can see in class MCoeControlObserver, both constructor and member data exit, but WHY Symbian itself doesnt obey its convention?

    Anyone can tell me ?

  2. #2
    Super Contributor
    Join Date
    Jun 2006
    Location
    Moscow, Russia
    Posts
    803

    Re: M classes can't have membership data?

    Yes, you are right. Docs from Symbian say:

    M classes have the following restrictions:

    * they should contain no member data

    * they should not contain constructors or destructors, or overloaded operators such as =
    But actually I do not see any reason why an M-class should not have a constructor because no heap-memory should be allocated in constructor in Symbian. So the main thing is, I think, that M-classes should not own heap objects.
    Regards,
    ivey

  3. #3
    Regular Contributor
    Join Date
    Jan 2004
    Location
    Braunschweig, Germany
    Posts
    345

    Re: M classes can't have membership data?

    Well, I cannot guess why Symbian is doing something, but I can put in my own opinion.

    M classes are meant to be just interfaces which only contains pure virtual methods. An interface is just meant as an concept which can be implemented by another class and does not have any implementation itself. When you have an M class with some implementation, you basically have a T class where you cannot create a instance directly and no M class anymore ;-)

    From the technical point of view there is no reason not to use Interfaces which have an implementation and even data members themselft, but you have to be aware that you might end up with the usual C++ multiple inhertance problems like diamond inheritance and so on.

    Bernd

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    12

    Smile Re: M classes can't have membership data?

    iVey and Bernd42, Thanks for your reply.

    I think both of you are right. As a developer, we maybe have to balance between Symbian convertion and C++ code style.

    Anyway, we should know what we are doing, even we define a M class with T classes or implemented methods.

    Do you think so?

  5. #5
    Regular Contributor
    Join Date
    Jan 2004
    Location
    Braunschweig, Germany
    Posts
    345

    Re: M classes can't have membership data?

    Of course it is your program and you can do whatever you want and you have to find the bugs you put in there ;-)

    For the M class with data members it depends where you want to use it. If it is just in a part of your application it is probably ok, but if you are using it in a library or a API you build to use in some other applications it is most likely a bad idea.

    Bernd

Similar Threads

  1. suckho, i have encontered the same problems. Could you tell me how you resolved it?
    By dicson_hu in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2005-12-09, 10:56
  2. GPRS connection problems on 6600..
    By suckho in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2005-12-02, 14:00
  3. Nokia 6600 Socket Server send delay Problem
    By dicson_hu in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2005-10-31, 07:37
  4. Replies: 2
    Last Post: 2004-09-15, 22:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×