السلام عليكم
أرجو المساعدة بخصوص عمليات القسر static_cast
:wacko: لأني لا أفهم فيها شي ؟؟
و شكرا
السلام عليكم
أرجو المساعدة بخصوص عمليات القسر static_cast
:wacko: لأني لا أفهم فيها شي ؟؟
و شكرا
السلام عليكم ,
اظن انك كتبت موضوعك "هناك مشكله صغيره في قسم ال c++" حتى تجد ردا على هذا الموضوع.
المشكله انك كتبت كلام محبط للبعض, و انت تسأل سؤال لو حاولت تبحث عنه بـ google لوجت الكافي و الوافي, ماعلينا <_<
static_cast
هو موضوع بسيط جدا , ببساطه, هذا المثال سوف يشرح لك الموضوع باكمله
#include <iostream>
using namespace std;
int main() {
int j = 41;
int v = 4;
float m = j/v;
float d = static_cast<float>(j)/v;
cout << "m = " << m << endl;
cout << "d = " << d << endl;
}هذا المثال يوضح احدى اهم استخدامات ال static_cast, الا وهو عندما يكون عندك two integers و تريد ان توجد خارج القسمه, فالناتج سوف يكون integer حتى لو كان هناك بالجواب فواصل, سوف تلغى و يعطى الجواب كـ integer
الحل هو ال static_cast انك تضع هذه الجمله static_cast<float> قبله القسمه فتحصل على الناتج الاصلي مع الفواصل
اذا كان هناك نقاط معينه تريد الاستفسار عنها, ارجو ان تذكرها
تم تعديل هذه المشاركة بواسطة Super_emad55 في 21 يناير 2007 في 01:31
ENG. IMAD, Programing is a way of life, It's in the air, we breath It's pumps through our veines, Without it, we soon crumble to dust
شكرا لك أخي على الشرح
لكن
اقتباساظن انك كتبت موضوعك "هناك مشكله صغيره في قسم ال c++" حتى تجد ردا على هذا الموضوع.
لا لم أكتب لأجد رد فلاحظ انه في هذا القسم لا يوجد سوى خمس مواضسع كتب عليها أخر رد اليوم بينما في قسم
vb كل الصفحة اليوم
اقتباسالمشكله انك كتبت كلام محبط للبعض, و انت تسأل سؤال لو حاولت تبحث عنه بـ google لوجت الكافي و الوافي, ماعلينا
المشكلة أني لست أفهم الإنكليزية
المهم, فهمت الموضوع ؟؟؟؟!!!!!!!!!
ENG. IMAD, Programing is a way of life, It's in the air, we breath It's pumps through our veines, Without it, we soon crumble to dust
بعض الشيئ
سلام عليكم
أنا كنت من قتره كتبت عن الكاستينج على المدونه الخاصة بي
http://neo-official.blogspot.com/2007/01/casting.html
أتمنى أنك تقراه و تستفيد منه
شكرا لك لكن الصفحة فارغة
سلام عليكم
http://www.ahmed-essam.com/2007/01/casting.html
Casting Peace be upon you when I was checking the code of Notepad++, I found something stops me, "reinterpret_cast", first of all i never had the need to know much about casting because I use so stuff like float BigNumber=15.12; int T = (int)BigNumber; anyways, when I start looking for this keyword I found it's amazing, there is a lot of ways of casting that make life more easier and more cool and more safe, here is the types of casting that I have found - dynamic_cast - static_cast - const_cast - reinterpret_cast - safe_cast every one do something cool, I will explain as I understand and for more details you can visit this link http://msdn2.microsoft.com/en-us/library/5f6c9f8h.aspx - dynamic_cast used with the casting objects, when it find that the object is not identical with the Type, it return null, I call this Safe casting, this protect your application from being crashed if you are casting objects that don't has the same type. - static_cast this type of casting I call unsafe casting, why because it just convert the pointer to the object type without regarding the original type of the object or the type, imagine that Car *CarObj; Bus *BusObj; Bus *NewCarObj= static_cast(CarObj); what just happen can cause a lot of troubles while you are running your application, why , simply you reference pointer to object not the same type, this why it's not safe and can cause troubles - const_cast this one is cool, suppose we have const varible, and for some reason you want to change it, use this casting operator it will do it for you. - reinterpret_cast this casting is used to convert the object address into integral type variable, this cast is not safe to use with casting objects back - safe_cast this one is for dot net guys so I am not going to talk about :D, I think the best 2 casting operators here is ( dynamic_cast - const_cast ) guys you can read more about it, but I mentioned it because I think it's important to know such things specially C++ Developers, thanks for reading this, please if you find anything not right please post reply and tell me :)
ممكن يكون اللاد يكون بطريقة أفضل
شكرا
شكرا لك اخي على المرور و سرعة الرد و أن شاء الله يمشي الحال
هذا الموضوع مغلق.