static_cast In C++
VloĹžit
- Äas pĹidĂĄn 20. 01. 2018
- JOIN ME
-----
CZcams đŹ / @cppnuts
Patreon đ / cppnuts
COMPLETE PLAYLIST
------------
C++ Tutorial For Beginners: ⢠Introduction To C++
STL (Standard Template Library): ⢠STL In C++
ThreadIng In C++: ⢠Multithreading In C++
Data Structures: ⢠Data Structure
Algorithms: ⢠Binary Search
Design Patterns: ⢠Factory Design Pattern...
Smart Pointers: ⢠Smart Pointer In C++
C++14: ⢠Digit Separator In C++
C++17: ⢠std string_view in C++...
C++ All Type Casts: ⢠static_cast In C++
INTERVIEW PLAYLIST
------------
C++ Interview Q&A: ⢠Structural Padding & P...
C++ Interview Q&A For Experienced: ⢠How delete[] Knows How...
Linked List Interview Questions: ⢠Find Kth Node From Bac...
BST Interview Questions: ⢠Search Element In Bina...
Array Interview Questions: ⢠Reverse An Array
String Interview Questions: ⢠Check String Is Palind...
Bit Manipulation Questions: ⢠Find Set Bit In Intege...
Binary Tree Interview Question: ⢠Invert Binary Tree
Sorting Algorithms: ⢠Bubble Sort
C++ MCQ: ⢠Video
C MCQ: ⢠What printf returns af...
C Interview Questions: ⢠Designated Initializat...
QUICK SHORT VIDEOS
-------------
C++ Short : ⢠C++ Short Videos
C Short : ⢠Shorts C Programming MCQ
In this video i have tried to explain static_cast in C++.
I have included 6 to 7 points to demonstrate the use static_cast in C++.
We use static_cast to check type casting at compile time. And it has more strict rules to check things at compile time.
In playlist we have covered all four types of typecast in c++ as follows:
static_cast in c++.
static_cast use in c++.
static_cast with example in c++.
what is the use of static_cast in c++.
#cpp #tutorial #programming #computerscience #softwareengineering
Hi everyone, Don't forget to hit LIKE and SUBSCRIBE button for more videos like this!!
And this will help me a-lot.
Why should i help people, everyone should help them self in good ways.
I don't want to make people handicapped by saying i will help you.
Sorry i don't believe in this.
@@SO-dl2pv he already helped so much by providing excellent content for free..u can at least be grateful for that
Man, found your channel, and as a C++ developer, I must say that your videos are very good. Subscribed!
Thanks for such a nice comment!
Hey can u help me at 3:49 how obj= 20 is done as I know if we want to pass any value to initialise data member through object is obj(20) but here obj = 20 I didn't get it
4:17 the output is misleading - the first operation is actually "conversion constructor" but it's been scrolled off the top of the window already. This leads to misinformation in the video that the first operation is "conversion operator"
I always go to your videos to get a more insight about a topic and you don't dissapoint.
Amazing gyan bro! Keep it up. Just one thing at 4:19 the video output displayed "conversion operator" first.
But actually conversion constructor should be called first(probably the output window size was the problem which scrolled up the first line).
Anyways conversion constructor would be called thrice, once during creation of the object, second time during assigning 20 to obj and third time during execution of static_castobj.
yes you are correct there should be 5 output lines but here we get only 4 I didn't notice that đ
3rd time during static_cast(30) not when static_castobj.
I came looking specifically for this.
This channel is a jackpot
Thanks for appreciation..
You have Int obj(3); so conversion constructed is called first. You just need to scroll up to see that line printed.
during point 2,I have a problem,the programm works only if i make a comment the two lines below, a)//return string str1(x); and b) //obj = static_cast(30);the output is, conversion constructor,conversion operator, conversion constructor,conversion operator.I can't find the solution of it.why it gives these two errors?
@CppNuts Which GCC version allows implicit conversion from char* to int*, i am using GCC 8.2.0 and it does give compile error in int *p = (int*)&c;
Don't know man!!
g++ (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
int main() {
char c = 'A';
int *p = (int*)&c;
printf("c=%d, *p=%d
", c, *p);
return 0;
}
$ ./a.out
c=65, *p=892260161
Maybe the memory allocation changed .....if my memory serves me right.char under the hood was 4 bytes giving off c-style casting from char to int possible....(early but it's just random gibberish)
one more question how to access abstract class non-virtual function in c++ and what is significance of it in real time programming .please reply
Good class thank you
In program 2, why don't we use the explicit keyword on the constructor so that it doesn't do implicit conversion?
But that is not the point here.
thanks for making this video
Welcome dude checkout other casting videos as well.
Thanks for this awesome video...
which book do you recommend for CPP?
No books, read as much as u can online.
Great work again...
Thanks man.. :D
Hey can u help me at 3:49 how obj= 20 is done as I know if we want to pass any value to initialise data member through object is obj(20) but here obj = 20 I didn't get it
I got the 4th point mentioned, but can you elaborate what are the problems that occur if we do such casting using C style casting. You mentioned it is dangerous, but what is the danger?
in C style type casting will change variable value, if you put c=9 and after casting, value is changes from 9->0
Yes in point 5we should not use static_cast, In COM i.e in QueryInterface we are using reinterpret_cast to jump here to there
Thank you sir. well explanation
Thanks..
good one ,thanks
Thanks Dude.
Can you please explain about point 4 (private inheritance).
For 1st one..
If suppose i entered a number then value to it will be assigned at runtime how will static_cast will operate that??
Static means static, it doesn't have anything to deal with at runtime and i know you know this, now coming to the question : if you pass number at run time then you must be having some data type for that number right?? so it will work on that data type not the number you have passed in.
i don't find repo of this on your github .Can you please paste the link ?
to_string(x): identifier not found.. I get a compiler error
does this mean polymorphism occurs only when a class is inherited public?
Kudos to u..super explaination always...just one clarification all kinds of pointer has same size but u mentioned couple of times char pointer has 1 byte size did u want to say char variable only
Yes i meant that only.
Good explanation
Thanks..
how can we access a non-virtual function in derived class from a base class pointer in c++, please explain.
+Vaibhav Gupta, simple way is to typecast base pointer to derive pointer.
fine , using static_cast or dynamic_cast we can do , but i think static_cast is preferable.....,Thanks
one more question how to access abstract class non-virtual function .please reply
Hey can u help me at 3:49 how obj= 20 is done as I know if we want to pass any value to initialise data member through object is obj(20) but here obj = 20 I didn't get it
Good explanation sir I love it
Thanks
Very good explanation â¤ď¸đ
Glad you liked it
Hi sir, Could you explain 4th point briefly?
Super like always...
Thanks..
9:39
4 ) *static_cast avoid cast from derived to private base pointer*
Could you please help me understand why it doesn't allow?
In the below scenario, this casting could be useful.
#include
using namespace std;
class Base{
public:
int x;
};
class Derived: private Base{
public:
void print() { cout
please I need an explanation about why shouldn't I use static_cast on privately derived classes
What IDE are you using?
It's Sublime Text Editor 3 (this is just editor)
If you are from windows you may have to download mingw for gcc compiler.
@@CppNuts Yes I'm from windows and i already have installed MinGW for GCC for Code::Blocks. The background colour and text formatting in this -IDE- Editor attracted me. Thanks for help anyway!
#include
using namespace std;
int main() {
// your code goes here
float f;
int a,b;
a=5;
b=2;
f=static_cast(a/b);
cout
a/b will produce int because a is int, use static_cast(a)/b to get the desired output.
thank you sir
integer pointer 8 byte not 4 byte (for 64-bit machine)
And thanks for this tutorial, đŤĄâ¤ď¸
i want to learn more about void pointers... :)
No problem i will upload video for that.. :)
Its Here: czcams.com/video/t9s6280XQ5Q/video.html
can u pls share link for conversion operator and conversion constructor
Did i said in video that i have covered this topic?
Because i am not able to find anything like that in my video list.
please do a video for conversion operator and conversion constructor...
czcams.com/video/j4iZ50lp9KM/video.html
Good explanation but font is very dull, please solve the issue
Thanks, i will try..
Hey can u help me at 3:49 how obj= 20 is done as I know if we want to pass any value to initialise data member through object is obj(20) but here obj = 20 I didn't get it
What? why would anyone wants to convert an int obj to a string obj? i just don't see a practical application.
Generally when you pass your data to web browsers then everything is going as string. This is one of the example.
what is wrong with (int) cast? why use such long word. the word static is now has different meaning in different context. now it has become one confusing F word. it is used in static class member. used in static function declaration. used in static variable local. compilation time now refers to static binding. there is static code analyzer. static has become confusing word.
gd class..
Thanks for the comment.
Change the background colour to white instead of black for IDE. Bcz letters are not visible properly.
Black color is still best. And best for our eyes too since has less blue light.
no wonder C++ is decreasing as a popular program language . why is it getting more F complicated? got your point but there got to be a better way.
When i saw this first time also felt the same way but when i started using them i found them so easy to remember and understand.
this video series is amazing. thanks to you. i am just frustrated with myself not understanding the real world application. there must be a good important reason for this.
too many adds , irritating
Sorry man!! can't help.
Use some more examples and try to explain slowly it seems like your your rushing somewhere
Oh i will try man, thank for the comment.
May be a good video for college students. Not an appropriate explanation for working professionals.
What is left plz comment, so working professional can get the benefitsđ¤đđ.
Person is speaking way too fast. I needed to change playback speed to 0.75
lot of examples you do not explain, you just copy pasted the whole example code from geeks for geeks. really shame man