casting

AS3: global var of type SimpleButton changes to DisplayObject for unknown reason, won't let me access .upState.textColor!

≯℡__Kan透↙ 提交于 2019-12-25 02:25:27
问题 This is a problem that's best explained in code. I don't see how active_button.upState , which I know is a TextField (see trace statements), mysteriously turns into a DisplayObject when I try to access the textColor property. I've included the error messages below for reference. Also, why is it that when I have an object that I know is a SimpleButton (again, see traces) I need to cast it to SimpleButton in order to store it in a var? That doesn't make any sense to me. All help is much

conversion from unsigned char* to const wchar_t*

拥有回忆 提交于 2019-12-25 01:53:25
问题 I am using the following code to convert a string from unsigned char* to const wchar_t* . The error I am getting is that only a few words are being converted properly while the rest is garbled value. CODE unsigned char* temp = fileUtils->getFileData("levels.json", "r", &size); const char* temp1 = reinterpret_cast<const char*>(temp); size_t len = mbstowcs(nullptr, &temp1[0], 0); if (len == -1) { } else { wchar_t* levelData = new wchar_t(); mbstowcs(&levelData[0], &temp1[0], size*10); } OUTPUT

C# - Can a List<MyClass> be seamlessly cast to a List<Interface> or similar?

天大地大妈咪最大 提交于 2019-12-25 01:46:03
问题 I have a DataSource in my control which is always a List<T> where T has to inherit from IEntity . public class MyClass<T> where T : IEntity { public List<T> DataSource { get; set; } } Now, obviously you can't cast a List<T> to a List<IEntity> doing the following: List<IEntity> wontWork = (List<IEntity>)this.DataSource; How can I get the DataSource as a List of IEntity , whilst still being able to add and remove items from the DataSource ? I.e. I could do the following, but removing from the

Cast auto_ptr<Base> to auto_ptr<Derived>

你说的曾经没有我的故事 提交于 2019-12-25 00:46:24
问题 Please help me to understand the following issue. Look at the code example below: #include <iostream> class Shape { public: virtual wchar_t *GetName() { return L"Shape"; } }; class Circle: public Shape { public: wchar_t *GetName() { return L"Circle"; } double GetRadius() { return 100.; } }; int wmain() { using namespace std; auto_ptr<Shape> aS; auto_ptr<Circle> aC(new Circle); aS = aC; wcout << aS->GetName() << L'\t' << static_cast<auto_ptr<Circle>>(aS)->GetRadius() << endl; return 0; } Why I

Typecast operator overloading problem

柔情痞子 提交于 2019-12-24 23:47:48
问题 For example i have two classes A and B, such that for two objects a and b, i want to be able to do : A a; B b; a = b; b = a; for this i have overloaded the = operator, and the typecast operators as: class A{ -snip- operator B()const { return B(pVarA); } }; class B{ -snip- operator A()const { return A(pVarB); } }; but when i try to compile this code, gcc throws the error : error: expected type-specifier before 'B' for the line: operator B()const { return B(pVarA);} my guess is, this is due to

Converting char to int without sign bit propagation in C++

做~自己de王妃 提交于 2019-12-24 19:41:23
问题 A byte of data is being stored in a 'char' member variable. It should probably be stored as an 'unsigned char' instead, but that can't be changed. I need to retrieve it through an 'int' variable, but without propagating the sign bit. My solution was this (UINT and UCHAR are the obvious types): void Foo::get_data( int *val ) { if( val ) *val = (int)(UINT)(UCHAR)m_data; // 'm_data' is type 'char' } This seemed the best solution to me. I could use *val = 0xff & (int)m_data; instead of the

Interpreting a uint16_t as a int16_t

删除回忆录丶 提交于 2019-12-24 19:37:58
问题 Is there a portable and safe way to interpret the bit-pattern made by a boost::uint16_t as a boost::int16_t ? I have a uint16_t , which I know represents a signed 16-bit integer encoded as little-endian. I need to do some signed arithmetic on this value, so is there anyway to convince the compiler that it already is a signed value? If I a not mistaken, a static_cast<int16_t> would convert the value, perhaps changing its bit-pattern. 回答1: If you are looking for something different than a cast,

Can you cast an object to one that implements an interface? (JAVA)

冷暖自知 提交于 2019-12-24 19:15:06
问题 Can you cast an object to one that implements an interface? Right now, I'm building a GUI, and I don't want to rewrite the Confirm/Cancel code (A confirmation pop-up) over and over again. So, what I'm trying to do is write a class that gets passed the class it's used in and tells the class whether or not the user pressed Confirm or Cancel. The class always implements a certain interface. Code: class ConfirmFrame extends JFrame implements ActionListener { JButton confirm = new JButton("Confirm

how to get output of a variable as float value

核能气质少年 提交于 2019-12-24 19:06:00
问题 i m having the follwing problem.. want to get the result in float suppose int a= convert.toint32(textbox1.text); int b= convert.toint32(textbox2.text); float ans= math.sqrt(a*b); label1.text= ans.tostring(); output.. a=7 b=3 ans should be= 4.582 but i get an error cannot implicitly convert type 'double' to 'float'. pls help..how can i get the float ans... 回答1: Change your code to double ans = math.sqrt(a*b); 回答2: double is just a larger float. Math.Sqrt() returns a double, not a float. You

Casting Object to Array in Java [duplicate]

混江龙づ霸主 提交于 2019-12-24 16:39:00
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How to convert object array to string array in Java I am receiving an Object and casting it into a String array like this: Object values[] = (Object[])request.getSession().getAttribute("userList"); String[] tmp = new String[values.length]; for(int i = 0; i < tmp.length; ++i) { tmp[i] = (String) values[i]; out.println(tmp[i]); } Is there any better and cleaner way to do this? 回答1: Why not directly casting? String