Results 1 to 5 of 5

Thread: Advantage of static_cast

  1. #1
    Join Date
    Nov 2009
    Posts
    67

    Advantage of static_cast

    Hello friends,
    I recently started learning c++ language. I want to know what are the advantage of static_cast. Because same type of work can be done with c type cast also. Can any one help to solve this confusion. Please help me. I want advantage of static_cast.
    Thank you.
    Last edited by Juaquine; 08-02-2010 at 05:07 PM.

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Advantage of static_cast

    It is very to use static_cast in your program. Using static_cast method you are able to convert from int to a char. But it has one disadvantage the resulting char doesn't have enough size to hold the whole value. It is easy to use static_cast over, but you also make sure that static_cast never do a run time check and for this reason sometimes error are unidentified. There for use dynamic_cast instead of static_cast.

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Advantage of static_cast

    There are various advantage of using static_cast over using c type cast. I have listed few of it . Just try to understand it.
    1. When you use static_cast method, then you are telling the user what you actually wanted to do.
    2. when you don't do daft things then compiler tells you that you have to do daft things before proceeding.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Advantage of static_cast

    I have written following program for you. In this program I have use static_cast method. Just go through each line and try to understand each line. At the end of this program you will bale to know what are the Advantage of static_cast.

    Code:
    class X {
    public:
    void CreateThreads ();
    private:
    void * MyThreadProc_ ();
    static void * SThreadProc_ (void s*);
    };
    
    
    void X::CreateThread () {
    pthread_t tids;
    
    pthread_create(&tids, NULL, &SThreadProc_, thiss);
    }
    
    
    void * X::SThreadProc_ (void *vx) {
    X *x = (X *)vx; 
    return as->MyThreadProc_();
    }

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Advantage of static_cast

    It is very easier to learn and execute code when you use C++ casts i.e. static_cast, because in this case each cast has a different intended usage. Using static_cast it is easy to find for casts which have a unique syntax. But you have to use static_cast very carefully, because they are sometimes leads to data loss. I hope my information will help you.

Similar Threads

  1. Advantage of getting GTX 680 FTW 4gb over 2gb?
    By Nguni in forum Monitor & Video Cards
    Replies: 2
    Last Post: 10-05-2012, 06:44 AM
  2. What is the advantage of WiMax technology
    By Galbraith in forum Technology & Internet
    Replies: 6
    Last Post: 27-05-2010, 09:35 PM
  3. How is Advantage Database Server
    By MaggieK in forum Software Development
    Replies: 5
    Last Post: 05-02-2010, 01:47 AM
  4. What is the advantage of TDK LTO?
    By Nalini_sh in forum Hardware Peripherals
    Replies: 3
    Last Post: 26-11-2009, 04:19 PM
  5. Wat is Advantage over B.com(MM)?
    By Saranbalaji in forum Education Career and Job Discussions
    Replies: 4
    Last Post: 30-07-2009, 10:57 AM

Tags for this Thread

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
  •  
Page generated in 1,713,880,612.20857 seconds with 17 queries