Hello,
Let's say i have a function that returns an object of type SomeClass. And i have code like this:
$test = function_to_return_someclass();
Now i want to use the $test variable in an IDE, but i want it to understand that $test is of type SomeClass. I can do it easily with class variables by using the /** @var */ comment, but this...
Eric Lippert's comments in this question have left me thoroughly confused. What is the difference between casting and conversion in C#?
...
All,
I'm doing some image manipulation in Scala by making use of BufferedImages and Raster objects. I am attempting to get all the pixels in the buffered image with the following code.
val raster = f.getRaster()
// Preallocating the array causes ArrayIndexOutOfBoundsException .. http://forums.sun.com/thread.jspa?threadID=5297789
// R...
I've got a piece of code in a project (MyProject) that contains early bound object from a referenced assembly (We'll call it CommonAssembly):
Dim myObject As CommonAssembly.MyEarlyBoundType
now I have another assembly that is dynamically loaded because it is not present in all projects:
Dim myLateBoundObject As Object = AppDomain.Cu...
In particular, will the following ever not work as expected:
typedef void(*func_p)(void*);
void foo(int* data)
{
printf("%i\n",*data);
}
int main(int argc, char** argv)
{
func_p bar;
int x = 42;
bar = foo;
bar((void*)&x);
return 0;
}
ie, can I rely on data pointers (void*, int*, struct baz*,...
You can upcast or downcast an instance (to a superclass or subclass) using this syntax:
var i:MyClass = MyClass(instance);
But what does the as keyword do?
var i:MyClass = (instance as MyClass);
Are they equivalent? or am I missing something here...
...
While I was trying to build a Number subclass in AS3 I noticed I cannot extend the Number/int/etc. classes --- they are final.
The next best thing was casting. Still, I also don't think this is possible but since I've been asking myself this for a while I said I'd ask here to find out.
Can you create custom casting for a class you crea...
What will be the output if I write
In C++ if(5) will be executed without any problem but not in C# same way will it be able to run.
if(func()){} //in C# it doesn't runs Why how does C# treats void and how in Turbo C++
void func()
{
return;
}
if(null==null){}//runs in C#
EDIT
if(printf("Hi"){} //will run and enter into if statemen...
Possible Duplicate:
When should static_cast, dynamic_cast and reinterpret_cast be used?
Until a few days ago, I've always used C style type casting in C++ because it seemed to work good. I recently found out that using C in C++ is very bad..
I've never really used C++ casting before, so I'm wondering if someone could tell me ...
I have following class:
template <size_t size>
class Araye{
public:
Araye(int input[]){
for (int i=0;i<size;i++)
araye[i]=input[i];
}
int araye[size];
};
How should I write a cast-to-reference-to-array operator for this class so that following works:
int adad[3]={1,2,3};
Araye<3> araye(adad);
int (&reference)[3]=araye;
...
I'm dividing some integers x & y in MS SQL, and I wan the result to be in a floating-point form. 5/2 should equal 2.5. When I simply do
SELECT 5/2
I get 2, which doesn't suprise me, since it's creating an int from two ints. I know I can force it to a float by doing:
SELECT CAST(5 AS FLOAT)/CAST(2 AS FLOAT);
but that seems like ...
I was reading some code that a consultant provided us. It's a bit convoluted, and at the end of a function, it reads:
return (int) 1;
Instead of:
return 1;
PHP has a lot of magic in it; is this as bone-headed as it looks, or is there a valid reason to cast an integer as an integer?
...
Hello!
Whenever I need to use the intelligence of Netbeans to show properties/methods, I explicitly declare a new object and then re-reference it. Something like..
$moo = new Cow();
$moo = Cow::getById(1);
$hasMilk = $moo->hasMilk();
Is there a way I can avoid this by type-casting the variable when getting it?
Or atleast a...
Possible Duplicate:
how to copy char * into a string and vice-versa
I have to pass a value into a method that required a char *
MyMethod(char * parameter)
{
// code
}
However, the parameter I need to feed it is currently a std::string. How do I convert the std::string to a char *?
std::string myStringParameter = //what...
Is the following code 100% portable?
int a=10;
size_t size_of_int = (char *)(&a+1)-(char*)(&a); // No problem here?
std::cout<<size_of_int;// or printf("%zu",size_of_int);
P.S: The question is only for learning purpose. So please don't give answers like Use sizeof() etc
...
Is there a more efficient way (preferably O(1) rather than O(n) but at least faster to type) to typecast the elements of a vector than this?
public Vector<String> typecastVector(Vector<Object> objects){
Vector<String> strings = new Vector<String>();
for(Object o : objects)
strings.add((String) o);
return strings;
}
...
I found in some legacy code I'm dealing with this function (in C++)
Vec3d Minimum()
{
if(this->valid)
{
return minBB;
}
else
{
return NULL;
}
}
where Vec3d is a object that is basically a struct with x,y,z and some operators overloaded (code below).
AFAIK, you can't return a 0 for a user define...
I'm trying to use QSharedPointer in my polymorphic stucture, but I couldn't find right syntax to convert pointer of base class to pointer of derived class.
struct Switch : State {
int a;
};
QSharedPointer <State> myState=QSharedPointer <State>(new Switch);
QSharedPointer <Switch> mySwitchTest= ??? myState;
What should I put in th...
Hello,
I have got a problem on casting an object to one of it's base interfaces living in another library. Here is the code for it:
BaseSDK.dll
public interface IPlugin
{
void Run();
}
CustomPlugin.Definition.dll:
public interface ICustomPlugin
{
void DoCustomStuff();
}
CustomPlugin.dll (has reference to BaseSDK.dll and Cu...
When I have two MongoDB documents like this...
db.test.insert( {"value" : "10123"} );
db.test.insert( {"value" : "160"} );
The result of a query like:
db.test.find({"value" :{$gt : "12"} });
is..
{ "_id" : ObjectId("4c6d1b92304326161b678b89"), "value" : "160" }
It's obvious, that a string comparison is made, so that my first va...