Results 1 to 4 of 4

Thread: typedef Related doubts?

  1. #1
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Thumbs up typedef Related doubts?

    Hi All,

    I am fresher to C++ programming, I want to know about why we need typedef ?

    now i am thinking it's only for programmers convinience , any other performance reasons

    please share your ideas,

    and i read in one tutorial about function alias using typedef as follows,

    typedef double (*Addition)(double value1, double value2);

    double Add(double x, double y)
    {
    double result = x + y;
    return result;
    }


    Usage:

    Addition plus;

    plus =Add;

    double ans = plus(3855.06, 74.88);

    In which suituations this kind

    of typedef for function alias will be helpful ?

    please help me to learn the typedef ?

    If you know any tutorial or books to learn usage of C++ concepts please let me know?
    Thanks,
    Rajesh.S

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: typedef Related doubts?

    Quote Originally Posted by rajeshs View Post
    In which suituations this kind

    of typedef for function alias will be helpful ?
    You use typedef to:
    • avoid errors by simplifying complex declarations,
    • avoid repetition,
    • provide meaningful type names and hide implementation details (for example iterator instead of node *).


    Quote Originally Posted by rajeshs View Post
    If you know any tutorial or books to learn usage of C++ concepts please let me know?
    See here: http://www.qtcentre.org/forum/f-gene...-books-29.html

  3. #3
    Join Date
    Jun 2007
    Location
    India/Bangalore
    Posts
    156
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Thumbs up Re: typedef Related doubts?

    Thank you very much for your valuable reply,

    now i am getting to know about typedef

    If any body knows about advantages of using function pointers please help me?
    Thanks,
    Rajesh.S

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: typedef Related doubts?

    Quote Originally Posted by rajeshs View Post
    If any body knows about advantages of using function pointers please help me?
    Function pointers are used when a value isn't enough --- you can use them to pass around different behaviours. The classic examples are qsort() and callbacks. In OO world, FP were replaced by functional objects (a.k.a. functors).

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.