×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    197

    Smile Use of struct and inline functions in Symbian OS

    Hi,every one,

    1.
    I think most of you have seen the following struct definition before.
    As far as I know, a data type of struct should not be like the following,
    it could not contain functions and friend class.
    Maybe I am wrong in the understanding of C++.
    Would some one give some explanations?
    Thanks very much.
    //========struct SCharacterSet definition start=============

    struct SCharacterSet
    {

    inline TUint Identifier() const {return iIdentifier;}

    inline TBool NameIsFileName() const {return iFlags&EFlagNameIsFileName;}

    inline TPtrC Name() const {return *iName;}

    private:

    enum
    {
    EFlagNameIsFileName =0x00000001,
    EFlagFileIsConversionPlugInLibrary =0x00000002
    };

    private:
    inline TBool FileIsConversionPlugInLibrary() const
    {return iFlags&EFlagFileIsConversionPlugInLibrary;}
    private:

    TUint iIdentifier;
    TUint iFlags;
    HBufC* iName;

    private:
    friend class CCnvCharacterSetConverter;
    friend class CDeepDestructingArrayOfCharactersSets;

    };

    //========struct SCharacterSet definition start=============







    2.

    I have studied C++ this far,but never saw inline functions defined outside class definitions before( namely, those inline functions do not belong to any class, they are independent. ).
    Why could define inline functions that way?
    Would some one give some explanations?

    These 2 problems confuse me for a long time, I should figure them out by your help.
    Thank you very much.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Location
    Oulu, Finland
    Posts
    1,122

    Re: Use of struct and inline functions in Symbian OS

    1) On language level, the difference between struct and class is just the default access mode. class members are private by default, struct members are public. On convention level, there are more differences between them (but it's always based on convention, not the language itself).

    2) See e.g. http://www.parashift.com/c++-faq-lit...functions.html

    Lauri

  3. #3
    Regular Contributor
    Join Date
    Oct 2007
    Location
    China
    Posts
    269

    Re: Use of struct and inline functions in Symbian OS

    hi,
    your two questions are all about C++, I think you would better strength your C++

    for your first question,
    laa-laa has explained, the only difference between struct and class is its default access model, the default model for struct is public and private for class.

    for your second question,
    I don't know what your
    (but never saw inline functions defined outside class definitions before( namely, those inline functions do not belong to any class, they are independent. ))
    means
    but I will tell you that the use of inline function is for the consider of efficiency of a program.
    a inline function can define in two ways, one way is all functions defined in a class is inline function, the other method is using inline key word before a function definition out of a class, in this way, inline function usually defines in the same head file as the class.
    I am a programmer,and I hope we can help each other and progress together

  4. #4
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Use of struct and inline functions in Symbian OS

    From a Symbian perspective that struct is incorrect as it owns a HBufC* and thus allocates memory and thus it must be a class deriving from CBase and not a struct.

  5. #5
    Registered User
    Join Date
    May 2007
    Location
    India
    Posts
    197

    Re: Use of struct and inline functions in Symbian OS

    Hi hotcheese,

    it is not necessory that if HBufC* is there in a class, it should be derived from CBase.

    It may be case that this struct holds reference of HBufC and it does not take ownersip. in which case, it is not necessory to derive it from CBase.

    Regards,
    Digish

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,674

    Re: Use of struct and inline functions in Symbian OS

    When you do not want to take ownership, you should rather store pointers/references of some base-type (TDesC or TDes, depending on the access you need).

  7. #7
    Nokia Developer Champion
    Join Date
    Jul 2004
    Posts
    2,015

    Re: Use of struct and inline functions in Symbian OS

    Quote Originally Posted by Digish View Post
    Hi hotcheese,

    it is not necessory that if HBufC* is there in a class, it should be derived from CBase.

    It may be case that this struct holds reference of HBufC and it does not take ownersip. in which case, it is not necessory to derive it from CBase.

    Regards,
    Digish
    That is true, and of course in object oriented design one class will frequently have a pointer to another class that it does not own. However I think if you apply that generic OOD principle to HBufC pointers I think in practice you would probably have a poor design and poor implementation and there would be a better and nicer alternative.

Posting Permissions

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