casting

cast e.Item.DataItem to typed dataset1.TableRow (Datagrid1_ItemDataBound event)

hi all, on http://www.dotnetjohn.com/articles.aspx?articleid=83 there is good example of using typed dataset though its in vb.net. I am not able to to the castings done in DataGrid1_ItemDataBound event in c#. Can any body help? datarow = CType(CType(e.Item.DataItem, DataRowView).Row, Dataset1.WorkExperianceDataRow) is the line with which...

question about virtual methods in java

Put simply: I want the following code to print "sub": Element e = new SubElement(); print(e); ... private static void print(Element e) { System.out.println("e"); } private static void print(SubElement e) { System.out.println("sub"); } and i dont want to change print(Element e). so nothing like private static void print(El...

Can't cast to to unspecific nested type with generics

I have two classes with nested generics. Is there a way to get rid of the Type mismatch: cannot convert from Msg<Value<String>> to Msg<Value<?>> error ? In the last assignment public class Value<V> { V val; public Value(V val) { this.val = val; } @Override public String toString() { return "" + va...

Dynamically casting one type of delegate to another

I'm using reflection to grab a field that happens to be a delegate. I need to replace this delegate with my own, but the type of the delegate is private (so I can't create it from my method and assign it) I have a delegate type with an exactly matching signature, so is there some way I can dynamically cast my delegate to this other type...

looping and casting problem in rails

I've got following method in User model def get_employees @employees = [] groups.each do |i| @employees << Group.find(i).employees end @employees end This is what the console prints when I call this method: > >> User.find(4).get_employees > => [[#<Employee id: 4, first_name: "test", last_name: "tes...

C++: can an int be assigned a char* ??

I am reading chapter 2 of Advanced Linux Programming: http://www.advancedlinuxprogramming.com/alp-folder/alp-ch02-writing-good-gnu-linux-software.pdf In the section 2.1.3 Using getopt_long, there is an example program that goes a bit like this: int main (int argc, char* argv[]) { int next_option; // ... do { next_option = g...

java: boolean instanceOf Boolean ?

Hello everyone. I'm a bit confused: I have a function, that takes an Object as argument. But the compiler does not complain if I just pass a primitive and even recognizes a boolean primitive as Boolean Object. Why is that so? public String test(Object value) { if (! (value instanceof Boolean) ) return "invalid"; if (((Boolean) v...

Reduce casting and better styling

Consider the following (nasty) code: /// <summary> /// Calls matching process error code on response.Code /// </summary> /// <param name="response">Actually will be of type Response or extend it</param> /// <returns>true for successful response, false otherwise</returns> private static bool ProcessErrorCode(objec...

How is it that U[] is castable to T[]?

It is clear that the T[] array type is not covariant as the elements of a T[] can be set by index. And yet, a U[] can be cast to a T[] without any complaints from the compiler as long as U derives from T. Man[] men = new[] { new Man("Aaron"), new Man("Billy"), new Man("Charlie") }; Person[] people = (Person[])men; In the above code i...

Type casting (from derived class)

Hello, I want to make chain-calling like jquery-way in c++. The sample: $('#obj').getParent().remove(); So, as I understand, each method of the class should return the pointer to himself (this). Everything is okay until I call base-derived methods. The code: class Base { Base *base1() { return this; } Base *base2() { return th...

Suddenly can't cast IWebProxy to WebProxy

I have some code that creates an IWebProxy and then casts it to a WebProxy. I ran my program and it worked. Then I inserted a break point and it all of a sudden stopped working and gives me the error: "Unable to cast object of type 'WebProxyWrapperOpaque' to type 'System.Net.WebProxy'." Another thing is that we use this method in 2 othe...

What class does the target object take on after casting?

OK, noob question. I'm studying for the SCJP and got 3 questions on object reference casting wrong which all seem to point to the same misunderstanding. Just wanted to confirm what the right insight should be. Right, here are the questions: 1. 1. class CodeWalkFour { 2. public static void main(String[] args){ 3. Car c = ne...

Converting array of objects to array of arrays

Hi, I have a Array of objects which is something like this : SomeObject (Array) [0] (object) id = 1 name = 'one' [1] (object) id = 2 name = 'two' I need it to be An Array of arrays , something like this : someobject (array) [0](array) id = 1 name = 'one' [1](array) id = 2 name = 't...

c bitwise negation conversion question

the following code: signed char sc = ~0xFC; unsigned char uc = ~0xFC; when compiled gives me the following warnings: integer conversion resulted in truncation integer conversion resulted in truncation why do i get these warnings how do i write my code, so that i dont get these warnings (without using #pragmas) thanx, i'm using ...

Is it possible to "constify" a field of `std::pair` without hacks?

In C++, the compiling the following code: std::pair <int, int> x; static_cast <std::pair <const int, int>*> (&x); gives an error: error: invalid static_cast from type ‘std::pair<int, int>*’ to type ‘std::pair<const int, int>*’ I more or less understand why it happens, as cv-qualifying a type in a template parameter list can, in pr...

postgresql 8.4 trigger/storedproc error : how to fix it ?

Hi there, An INSERT on a table triggers a stored proc where the following error occurs. ERROR: column "targetedfamily" is of type boolean but expression is of type character varying Hint: You will need to rewrite or cast the expression. Where: PL/pgSQL function "fn_family_audit" line 19 at SQL statement And here's the ERRING stor...

Casting one object to another

I have to Classes. lets say Invoice and TempInvoice. Both have same properties(all are same). let say i created a object using Invoice Class. Can i cast that object to another object that i created using tempInvoice ?? ex: Invoice invoiceobj= getInvoice(int? id) //a method return a invoice object TempInvoice tempInvoiceObject = invoic...

Casting "Stylee"

From the book Exceptional C++ Solution to ch. 44 I've learned that they are situations when none of the new cast styles would work properly. I always thought that they (those 4 new casts) cover every possible situation and there is no need for "old" style cast anymore, but it appears to be not true. So my question is: Are those new casts...

Is there any way to provide constructor parameters to generic instances?

I can't do this in C#: catch (Exception exception) { var wrappedException = new TException(exception); } Getting error "cannot provide arguments when creating an instance of type parameter 'TException'. Just wanted to check with the community to see if there is any way to do something like this? ...

adapting an old-fashioned cast of a std::streampos to be g++ 4.4 compatible

Good afternoon, I'm attempting to get some old-fashioned code to function in g++ 4.4. My understanding is the code compiled fine in g++ 4.0, but g++ has become more strict between 4.0 and 4.4. This code in particular causes the compiler to stop and complain: sprintf(s,"%.7d",(long)tellp()); tellp() is a std::streampos object. The ab...