i am writing a macro to convert the zeros in the access table to "0000"
Zero is text data type so i cast it to int in the if condition to update the records which is only zeros and preventing it in updating records which are non zeros
but now all the records are getting updated ..if clause is calling all the time even there is a value...
How do I cast an instance of an object and actually make it that type of object?
I have a class myClass1 that is the base class for myClass2 and myClass3. I want to use myClass1 for auditing, for auditing all I want is the data from myClass1. Because myClass2 and myClass3 inherit from myClass1 you can set an instance of myClass1 to an...
public void wahey(List<Object> list) {}
wahey(new LinkedList<Number>());
The call to the method will not type-check. I can't even cast the parameter as follows:
wahey((List<Object>) new LinkedList<Number>());
From my research, I have gathered that the reason for not allowing this is type-safety. If we were allowed to do the above, ...
Just read on an internal university thread:
#include <iostream>
using namespace std;
union zt
{
bool b;
int i;
};
int main()
{
zt w;
bool a,b;
a=1;
b=2;
cerr<<(bool)2<<static_cast<bool>(2)<<endl; //11
cerr<<a<<b<<(a==b)<<endl; //111
w.i=2;
int q=w.b;
cerr<<(bool)q<<...
Once in a while, I find myself rounding some numbers, and I always have to cast the result to an integer :
int rounded = (int) floor(value);
Why do all rounding functions (ceil(), floor()) return a floating number, and not an integer ? I find this pretty non-intuitive, and would love to have some explanations !
...
I'm receiving a dict from one "layer" of code upon which some calculations/modifications are performed before passing it onto another "layer". The original dict's keys & "string" values are unicode, but the layer they're being passed onto only accepts str.
This is going to be called often, so I'd like to know what would be the fastest w...
Suppose I have two classes with identical members from two different libraries:
namespace A {
struct Point3D {
float x,y,z;
};
}
namespace B {
struct Point3D {
float x,y,z;
};
}
When I try cross-casting, it worked:
A::Point3D pa = {3,4,5};
B::Point3D* pb = (B::Point3D*)&pa;
cout << pb->x << " " << pb->y << " " << pb-...
I have the following enum -->
public enum SyncStatus
{
Unavailable = 0,
Checking = 5,
StartedAspNetDb = 10,
FinishedAspNetDb = 20,
StartedMatrixDb = 30,
FinishedMatrixDb = 40,
StartedConnectDb = 50,
FinishedConnectDb = 60,
StartedCmoDb = 70,
Finished...
I have code like:
var t = SomeInstanceOfSomeClass.GetType();
((t)SomeOtherObjectIWantToCast).someMethodInSomeClass(...);
That won't do, the compiler returns an error about the (t) saying Type or namespace expected.
How can you do this?
I'm sure it's actually really obvious....
...
You can see what i'm trying to do below:
typedef struct image_bounds {
int xmin, ymin, xmax, ymax;
} image_bounds;
#define IMAGE_BOUNDS(X) ((image_bounds *)(X));
typedef struct {
image_bounds bounds;
float dummy;
} demo;
int
main(void) {
demo my_image;
/* this works fine */
((image_bounds *)(&my_image))->xmin...
Hi
Why can I not cast a List<ObjBase> as List<Obj>? Why does the following not work:
internal class ObjBase
{
}
internal class Obj : ObjBase
{
}
internal class ObjManager
{
internal List<Obj> returnStuff()
{
return getSomeStuff() as List<Obj>;
}
private List<ObjBase> getSomeStuff()
{
...
I'm trying to pass a 2D array of char* into a function. I am getting this error:
"cannot convert 'char* (*)[2]' to 'char***' for argument '1' to 'int foo(char***)'"
Code:
int foo(char*** hi)
{
...
}
int main()
{
char* bar[10][10];
return foo(bar);
}
...
Hello
How can I locate all old C-style cast in my source?
I'm using Visual Studio, may be there is some compilator warning that I have to enable? Or use some software tool for this?
...
I have a set-up similar to WPF's DependencyProperty and DependencyObject system. My properties however are generic. A BucketProperty has a static GlobalIndex (defined in BucketPropertyBase) which tracks all BucketProperties. A Bucket can have many BucketProperties of any type. A Bucket saves and gets the actual values of these BucketProp...
I was checking the behavior of dynamic_cast and found that when it fails, std::bad_cast exception is thrown only if the destination is a reference type. If the destination is a pointer type then no exception is thrown from the cast. This is my sample code:
class A
{
public:
virtual ~A()
{
}
};
class B : public A
{
};...
I am new to developing with Visual Basic, but have lots of experience in C#/C/C++/JAVA/Haskell and a few others.
Is there some reason I am maintaining code and finding code examples where the type declaration just seems lazy? I have seen countless Strings, that are only ever used as the String type, declared as an object. Before the o...
I'm using two 3rd party libraries, which both implement their own 2D vector class. Unfortunately, I have to work with both of them, so is there anyway I can write some "friend" functions so that one can automatically be converted to the other when I try to use them in functions from the other library?
...
I know that converting a pointer to one int is unsafe, because the pointer can be bigger than the int in some architectures (for instance in x86_64).
But what about converting the pointer to several ints, an array of them? If the pointer size is 2 times bigger than int then convert pointer* to int[2].
The number of needed ints then is ...
Hello!
I am using Convert.ChangeType() to convert from Object (which I get from DataBase) to a generic type T. The code looks like this:
T element = (T)Convert.ChangeType(obj, typeof(T));
return element;
and this works great most of the time, however I have discovered that if I try to cast something as simple as return of the followi...
I have a key/value pairs mapped by hash (ID) in Dictionary<string, Dictionary<string, string>> called id2key_value. You can think of this as a way to represent database-like table with rows.
I added some helper functions to ease the use of some basic datatypes by doing a cast, like
public int GetInt(string id, string key)
{
int val...