I asked a question recently regarding a http://stackoverflow.com/questions/3863657/peculiar-behavior-of-immediate-window-in-vs-2008 peculiar behavior that I observed in the immediate window. After some debugging I found the issue the following example can reproduce the same.
// SimpleClassLib.dll
namespace SimpleClassLib
{
...
I'm trying to write a generic method for fetching an XElement value in a strongly-typed fashion. Here's what I have:
public static class XElementExtensions
{
public static XElement GetElement(this XElement xElement, string elementName)
{
// Calls xElement.Element(elementName) and returns that xElement (with some validati...
Possible Duplicate:
When should static_cast, dynamic_cast and reinterpret_cast be used?
what is the difference between those two casts,
const_cast<const A&> and static_cast<const A&>
what do You usually use in your practice? thanks in advance
...
class B{
private:
int a;
}
class D: public B{
private:
int b;
}
B* b = new B;
Now for some reason I want turn b into a D* Type of Object.
e.g. retain the information of B and become D with extra Informations required.
What I am currently thinking of is. static_cast to do the upcasting. the additional attributes will be se...
I saw a below code:
Map(1 -> "one", 2 -> "two") map _._1
this return a Iterable[Int], but if I want to do nothing with map, how to do it?
I want to do something like below, but the below code can't compile, I know because it a object instance not a function, but how to create a function to do x => x and use placeholder:
Map(1 -> "on...
Transitioning from C++, I am now learning the dark art of C and have developed the following code to replace my need for templating. In the bottom example, I have implemented your garden-variety Node structure in such a way that it can be used to store any data type. Consider the following...
// vptr.c
#include <stdio.h>
struct Node
{...
Hi All, I want to create a method which will take some base type as a parameter and compares and check if it is derived type and return the derived type based on that.
For Example:
Class A : IBase
Class B : IBase
My method:
Public IBase GetData(IBase type)
{
If type is A then
{
//do smthing
return A
}
If type is B
{
...
Quoted from here:
CMediaType mymt;
AM_MEDIA_TYPE pmt = (AM_MEDIA_TYPE*)&mymt;
Why can a CMediaType object be cast to AM_MEDIA_TYPE?
Is such feature available in c?
UPDATE
Can someone answer it seriously what's the principle behind cast subclasses to their base classes, can I do it the other way around?
UPDATE2
AM_MEDIA_TYPE/C...
Possible Duplicate:
pointer to a specific fixed address
An interesting discussion about this started here but no one have been able to provide the C++ way of doing:
#include <stdio.h>
int main(void)
{
int* address = (int *)0x604769;
printf("Memory address is: 0x%p\n", address);
*address = 0xdead;
printf("Content o...
i have a code as
public class BooleanTest {
public BooleanTest() {
super();
}
public static void main(String args[]){
BooleanTest bt = new BooleanTest();
bt.doProcess();
}
private boolean method() {
return false;
}
private void doProcess() {
Boolean obj = (Boolean)method...
Hi all,
I'm a C++ programmer and have a need to set up some UDP communications between a java android app and the C++ server running on a PC.
I have structure that I need to receive on the PC that consists of the following:
int
int
float
Unfortunately I'm totally at a loss as to how I can do this with Java.
I need to create a Datag...
Right now, I have:
public <T> T[] toArray(T[] old) {
T[] arr = Arrays.copyOf(old, old.length + size());
int i = old.length;
for(E obj : this) {
arr[i] = old.getClass().getComponentType().cast(obj);
++i;
}
return arr;
}
(Note that this does not follow the contract ...
This is a beginner's question, but I am interested in learning what's going on here. My question is, what goes on behind the scenes when you down-cast an object? Does it maintain some sort of metadata about what it originally was? Here's what I mean:
Suppose I have a method called "ClockIn" that accepts a parameter of type "Employee":
...
If I do:
int i=3, j=10;
float f;
f=(i+j)/2;
so f won't get value 6.5 but 6.
But,
f=(i+(float)j)/10;//edited
would be f=6.5.
What is the place where this temporary values are stored and why do we need to type-cast?
...
Hi!
I've used the following C macro, But in C++ it can't automatically cast void* to type*.
#define MALLOC_SAFE(var, size) { \
var = malloc(size); \
if (!var) goto error; \
}
I know, I can do something like this:
#define MALLOC_SAFE_CPP(var, type, size) { \
var = (type)malloc(size); \
if (!var) goto error; \
}
But ...
Hi,
I have Hibernate method which returns me a BigDecimal.
I have another API method to which I need to pass that number but it accepts Integer as parameter. I cannot change return types or variable types of both methods.
Now how to convert the BigDecimal into Integer and pass it to second method?
Is there a way out of this?
...
I have two classes, obstacle and boid, boid inherits from obstacle.
Now I want to write some functions that can work with objects of both classes, so that passing vector<boid> does work as well as vector<obstacle>.
When I typecast like this and try to access the size of the vector I get a number of 1840700394 instead of 60:
vector<boi...