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.
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.
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_();
}
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.