Casting is a process where an object type is explicitly converted into another type if the conversion is allowed.

learn more… | top users | synonyms

0
votes
0answers
7 views

provisionary polymorphism or cast?

I have interpreter, which passes the values through the stack. The procedure expects that value is of specific type. It looks something like ...
-1
votes
0answers
24 views

Default Keyword cause namespace issue [closed]

I'm trying to do a simple null check on an unknown type so I'm dynamically changing its type in the following function. Everything is cast as objects right now to simplify testing. However the ...
10
votes
3answers
227 views

Avoiding code duplication and retaining const correctness

Sometimes I run across the problem of having two member function overloads that only differ in the constness of this (and the return type, but that is less ...
5
votes
2answers
71 views

Avoiding casts in abstract types

I asked this question on Stack Overflow and in the comments someone had this to say. In a proper design, you should almost never have to do a dynamic_cast, even if it's hidden inside some nice ...
3
votes
3answers
63 views

Limited typecasting with regex

long time user/lurker at stackoverflow, first time here. I've seen a lot of questions like this have people point to this section of the StackExchange network so I hope this is the right place. I'm ...
4
votes
1answer
117 views

Different Constructors, Same Implementation

I have this class containing two constructors with different signatures but they do the same thing: ...
1
vote
1answer
117 views

Can casting to fragment be more efficient than using a variable?

I'm new to using fragments in Android. I'm working on an app using a sliding panel layout and I just came up with an idea for changing my fragments. I decided to create the following method: ...
4
votes
2answers
342 views

Pointer casting. Correct alignment and code style

There is a function that converts region code strings (1 to 4 characters and null terminator) to 32 bit integers codes to be used in maps as keys or values. Blindly casting char* to int* is bad as it ...
6
votes
1answer
133 views

Is this a conforming implementation of duration_cast?

Sadly VS2012's duration_cast is broken, and I actually need the functionality which is broken. So, I wrote my own: ...
2
votes
1answer
62 views

Are my implicit type conversions correct?

I'm having some issues with my code and I'm trying to rule out any syntax or programming mistakes. One of the things I'm trying to rule out is the different variable types used in my equations. I'm ...
4
votes
1answer
176 views

Collection of Actions

I am trying to create a class to queue up a series of commands. (Not really a queue as events happen based on time). Each command has a callback (Action) that get's called. However, each Action has a ...
2
votes
2answers
86 views

Could I get rid of all these downcasts?

For a homework assignment we have to write a class that simulates water breaking a floodbank (very simplistic 2D simulation). My implementation works fine but I found that there were many downcasts ...
3
votes
1answer
158 views

Returning a more specific class

I would appreciate some feedback on my design of a few classes to query the Trakt.tv API. ...
8
votes
1answer
1k views

Improve my TryCast<T> method

This isn't urgent, it is more along the lines of trivia or a challenge. The solution works fine as it is, but I suspect it could be better. What follows is a method I came up with a while back in a ...
2
votes
2answers
66 views
10
votes
3answers
202 views

Cast inside the method or let the client code cast, which one is better?

I have two choices of implementing a method, the first one is a generic type where the client code does not have to cast ...
1
vote
2answers
897 views

(sort of) casting types in Ruby: changing class of an instance [closed]

I defined the class Rectangle: ...
2
votes
1answer
104 views

Is it safe to cast a pointer to non-void function into a pointer to void function?

I thought it was a good idea to use this in my C++ projects: ...
4
votes
1answer
97 views

Demonstration of pthread calls

Please review for any unnecessary casting, memory leaks, wrong use of pthread call, or validation problems in the given code. ...
2
votes
1answer
85 views

Nice way to using cast on TextView [closed]

Question is short. Assuming that I don't need reference itself, would this cast ((TextView) findViewById(R.id.someTextView)).setText("lala"); be better (or at ...
1
vote
1answer
491 views

Loading an Object from File with Type-Safety and Thread-Safe access

I'm attempting to write a bit of code that allows for easy and safe access to objects in a file. It seems to work great but I was curious if there was an easier way to do this or if Java already has ...
3
votes
1answer
371 views

Is there a better way to cast between decimal and generic in this C# code sample?

I have written a helper method which computes the sum of values in some custom grid, given the column indexes. The method appears to work (for a decimal - as Anthony pointed out, I need to test this ...
1
vote
2answers
93 views

Over-Riding User Input

Here's a trivial example: if type(length) != int: length = 16 as opposed to: ...
1
vote
1answer
1k views

Casting const pointer to non-const pointer when using struct iovec

struct iovec is defined in <uio.h> by the following way: ...
3
votes
2answers
2k views

Is this a proper way to check a viewstate of type int?

In page load I'm saving a query string int value in a viewstate. Then I save it to my DB. Here is the code I use to retrieve viewstate value and validating it: ...
9
votes
2answers
308 views

C++ int_cast<> function for checked casts?

In order to detect run-time integer casting problems, I've created this function*: ...
2
votes
2answers
154 views

A way to do this without a lot of variables and casting?

Currently I have this code: ...
4
votes
1answer
419 views

How to avoid unchecked cast warning in my generic recursive Iterator in Java

Somewhat odd that Java's collection framework has no iterator for recursive data structures... Since I needed something like this, I wrote my own. First of I need recursive elements: ...
3
votes
4answers
210 views

Euclidian distance - optimization and casting

I'm trying to optimize a simple Euclidian distance function in C. It's for a DLL, and calculates distances from one point to many. I have: Version 1: ...
9
votes
2answers
495 views

Loops for removing unnecessary lines

I have the following method: ...