What is costing in C++ | explain in epic and easy way 2021

Costing

Today we are going to be talking about costing in C++ we really haven’t talked about this often although we have in fact use costing I will talk more about kind of cease all costing as well as the C++ stuff costing and is this fair one call absolutely everything will get into this as a serious kind of goes on and I think that this topic is one of those things that you just have to practice with and kind of learn from experience rather than me just telling you this is how it works because if you just take in the theory with my practice so this specific topic it’s not really going to help you that much Sir just give them I can’t cook so first of all what is costing well what I’m talking about costing I’m specifically talking about type costing or any kind of conventions that we have to do within the type system that we have available to us into a ++ being a strongly typed language basically just means that. There is a type system and Hudson falls if I make something as an integer I constantly just stop treating it as if it was a double or Florida or something like that vice versa I have to kind of stick to my time unless there’s an easy implicit conversion which means that this simple knows how to convert between the 2 talks with no job loss and basically was labeled as an implicit conversion as well or as an explicit conversion which is why I’m actually telling us Hey you need to convert this type into this type.  Costing Costing

Now we have covered kind of costing and type investments to an extent when we talk about type punning so if you haven’t seen that article definitely check that out but in this article we’re going to kind of formally cop couple what costing actually means and see how we can start the way that would be fun talking about insisted we explicit talk conventions is one of 2 ways really are these I see it as one of 2 ways that is the kind of cease all costs and then we also have a C. ++ top costs now if we just take a look at quick example I just happened into junk like this holiday and also able to 5 and I want to I want to trade as a double now in this scenario if I make a double gold value. Is that a good day you can see that that we don’t need to explicitly specified Hey I want you to come that aids would double because that’s and that’s kind of a convention that it deems as implicit it’s easy to do does not tell us anything like that now if I had something the other way around swear I had maybe double value equals like 5.35125 or something like that and I wanted to give that into a instructs that would also be deemed as an implicit conversion because it’s not something that we necessarily have to specify Hey I’m giving this topic at this time now if we didn’t want to be explicit for example well we can actually do it’s just cost this double into an integer by doing something like this right now of course in this case it implicitly them to do that but for the sake of this let’s and since we are talking about crossing let’s pretend it wasn’t so we have an implicit we have an explicit conversion here because the thing I want is value to be conveyed into shop now why we need this is kind of.  Costing Costing

It’s not really that’s a better example might be like if we wanted to maybe have another double yeah cold AJ and we want to ask you know where 5.3 to this value now if we just kind of get rid of this printer what They actually is than what you might say it’s always the way you might expect with kind of adding 5.25 to 5.3 now if I cost this value into an integer that’s going to combat into an integer which means going to truncate the point 25 and I’m just being 5 plus 5.3 which instead of giving us 10.55 would give us the value of 10.3 and in this case is actually changing it and this actual technique that we’ve used is called to say style costs because we basically specify the popular crossing to interested like this and then the variable or actually costing optionally we can of course surrounded in.  Costing Costing

For instance like this which is particularly useful if maybe 1 of the cost of that entire thing into it and once it had actually value it in fact we do this we’ll still get 10 as the value because value is going to be 5.25 plus 5.3 which gives us 10.55 and then it would get truncated into intense now the simple fuss way of doing this would be by using a single fall stuff cost and specifically for this that would use something called a static cost on and do that basically this would look like the following so I mean just get back to where we were before which is just this. And it’s been this would just pay a static cost lower cost me into which is an answer and then the value and then we have 5.3. And that would be our value now symbols pasta costs we have a number of them one of his call center because we have something else called rate separate cost yes legal dynamic cost and we also have something called cost cost is kind of the 4 major costs now we have to realize is that they do not do anything that sees all costs can alter.  Costing Costing

What I mean by that is that sure they might do a divisional things but the actual convention the result of what you get is a successful type conversion cease all calls can achieve all that so this isn’t really adding new functionality what it is adding it’s kind of like syntax sugar to your card now of course dynamic cost which we’ll talk about specifically in Aleve also showed example that working here but we’ll talk more in depth about what actually does and how it works another article that for example will actually perform a check and may return null if the convention wasn’t successful so it does do extra things which also means that actually comes close you down but for the for the most part all of the C. bus stop costs don’t do anything really extra they just kind of our way to put into English words static cost for example but it’s a static cost and they also do some other compile time checks in the case of static cost to see if that compassion is actually edible and a possible and reinterpret costs as well it’s kind of putting into words the whole time the thing that we talked about it’s just a way to put it into words like retirement costs on rain tempering this memory as something else calls costing.

I’m removing calls on adding cost the benefit to having all these costs apart from those kind of compile time checks that you might receive is you can now search for them in your cart base right if I want to see where I could wear my costing is maybe I having performance issues and I want to know it’s dynamic cost something I can search for done and cost I can search for static cost if you just have a cost like a seesaw cost like into whatever like we did with that previous example how you assess that you can’t really search for some time you can because you could use like a red jacks or something like that and actually just. I don’t I just it wouldn’t actually be practical to do that what is here we’ve got actual English whites that are very easy to search for so it just helps on board as a programmer reading out and running a card but we’ll start it helps us to reduce kind of errors that we might accidentally making for trying cost I said considering incompatible the example as we’ve got a few classes here banks derived in another class if I was trying to cross this value which is clearly Indians into life partner and now the class that’s going to result in an Arabic as well and again this case going to be because of the construct up quite a fight like points or something like that not to this case you can see is an invalid type convention so. Costing Costing

What’s the focus is down as the compilers looks bad men like that’s never going to work right and even if we do take the memory address off it right which of course gives us any point time we’re trying to type on it that’s not going to work it’s an invalid type convention now folk type money as I just explained we would need to use rain temper costs and if we do you can see we don’t get any errors now reinterpreted the that the daughter that is at that value points up into being appointed to in another class instance but the point is with things like this it adds actual compile time checking because it knows that we Kant to 7 conventions where is this wouldn’t be a case of course if we just use a normal system because it would just kind of fall to doing water rates have been costly I don’t think a lot of whites and it might be a little bit hard to follow but again the best way to talk to actually learn this stuff is a practice that. Try and build yourself an example of using static cost bearing temper cost a cost because the dynamic consul Showtime caught a constant example imminent but stranded itself and then that’s the best way to kind of work out how it actually works and when you can use each one so we take a look at dynamic costing.

What and apes flex leader Is suppose that we had maybe we made a derived class instance right so I said derived derive peoples need arrived and then somewhere along the line I decided to actually cost that into a base right Sir a bank basically derived. Now what I want to do laid out is figure out okay Hey I have a base points out is actually derived instance or is it and all the classes and students say they both extend banks now if I am trying to use it what I can do it dynamic cost is actually kind of not only asked that question but attempts that confession and do something if it fails so we know for a fact based on this card that base is actually an instance all of the derived class but let’s pretend that we didn’t know what to say another class Stacey equals dynamic cost. Another class. And then they say right Planters. 

Okay now what’s going to happen here is if we had just use add static cost we find a way we can see we can do in this case it does the same thing as a Facebook cost or if we use the sea salt coffee which is what I like is it you would just give us that value and of course things might go wrong later on because your AC is not in fact on the classes actually arrived instance which is basically type on that but with dynamic cost what’s actually going to do is going to see if that is actually the case and of course every here and to make sure our costs and base and all I see that’s about 5 and see what happens. So you can see what’s actually do that if I have 10 I see the eagles now because it is in fact not back and of course you can check if you could say if not I say ours icicles now then maybe we know that it’s not that close or away check for if it is that classes just to say if a state that means the type conventional successful and we now know that there is in fact an instance and instance of derived right now I’m sorry an instance of the cost. And of course if I do changes around so it works by sending people to drive to. 5000000 safe I have tenure it doesn’t factor also valid points out because that conventional successful so damn across is a great way to see if it’s actually what now this does tie in very closely to the runtime type information RTI and it requires a whole bunch of things we will talk about in a specific article Boston and costing but just so.

You know he’s costing operate as a kind of available to you as a way to simplify costing and to maybe make it more solid in the sense that you will be compiled time checking dynamic costs will do run time checking and you’ll get old all that kind of hopefully more solid code base by using customers like that me personally I tend to use a cell costs most of the time but I do encourage if you’re working on a brand new project that you’re starting from scratch if you have a very small projects you should use a stylus SRC bus stop costing like that cost and the cost reinterpret cast well that kind of stuff because those costs. What do you make your card most solid and our backs up for everyone involved really and cost constantly touch on but that’s just naturally use it to add or remove cost to something easy you can add constant pleasantly anyway but it’s mostly for making calls and again it’s good to just have in your code base because now you can search folder nobody times you decided to remove cost and maybe fix that or just come up with something else as well so that’s really useful and then the other thing was rain temper cost if you look that type 20 article directly into the beginning of this article everything I did that you can make these right have a cost of that kind of desperate to have a cost is used for it’s when I don’t actually want to convert anything I just want to take that kind of point to and interpret it as something else someone interpret existing memory as in all the time that’s where a typical species anyway have you guys enjoy this article stating that like button you have to put the series back and has been on hold since the Cherokee shout out to everyone.

Also See

What are Classes in C++ | Top and latest explanation 2021

Leave a Comment

Your email address will not be published. Required fields are marked *