Search Results

Search found 8446 results on 338 pages for 'dynamic cast'.

Page 104/338 | < Previous Page | 100 101 102 103 104 105 106 107 108 109 110 111  | Next Page >

  • How to cast an NSDecimal value into an NSInteger value?

    - by mystify
    I have an situation where I get an NSDecimal, and I need an NSInteger. I do know it is a very small value (this is absolutely sure). It won't be bigger than 100. So It would be perfectly fine to cast it to NSInteger, no overflow would happen. How could this be done? There's just an -doubleValue method in NSDecimal.

    Read the article

  • How do i cast an object to a string when object is not a string?

    - by acidzombie24
    I have class A, B, C. They all can implicitly convert to a string public static implicit operator A(string sz_) { ... return sz; } I have code that does this object AClassWhichImplicitlyConvertsToString { ... ((KnownType)(String)AClassWhichImplicitlyConvertsToString).KnownFunc() } The problem is, AClassWhichImplicitlyConvertsToString isnt a string even though it can be typecast into one implicitly. I get a bad cast exception. How do i say its ok as long as the class has an operator to convert into a string?

    Read the article

  • Should I cast variables that use a typdef'd type?

    - by mesorismo
    If I have something like: typedef int MyType; is it good practice to cast the operands of an operation if I do something like this: int x = 5; int y = 6; MyType a = (MyType)(x + y); I know that I don't need to do that but wondering if it's better for intent/documentation/readability concerns.

    Read the article

  • Why cast null before checking if object is equal to null?

    - by jacerhea
    I was looking through the "Domain Oriented N-Layered .NET 4.0 Sample App" project and ran across some code that I do not understand. In this project they often use syntax like the following to check arguments for null: public GenericRepository(IQueryableContext context,ITraceManager traceManager) { if (context == (IQueryableContext)null) throw new ArgumentNullException("context", Resources.Messages.exception_ContainerCannotBeNull); Why would you cast null to the type of the object you are checking for null?

    Read the article

  • In asp classic: How can I make sure that a variable can be cast as an int?

    - by Tchalvak
    The following function was suggested to me: ' Defines a forced casting function, which "casts" anything that it can't detect as a number to zero. Function MakeInteger(val) If IsNumeric(val) Then MakeInteger = CInt(val) Else MakeInteger = 0 End If End Function Unfortunately there appear to be some things that return true for IsNumeric() but still can't be cast as an int. Is there any better check to use?

    Read the article

  • Do I need to cast the result of strtol to int?

    - by Kristo
    The following code does not give a warning with g++ 4.1.1 and -Wall. int octalStrToInt(const std::string& s) { return strtol(s.c_str(), 0, 8); } I was expecting a warning because strtol returns a long int but my function is only returning a plain int. Might other compilers emit a warning here? Should I cast the return value to int in this case as a good practice?

    Read the article

  • Why does the 'as' keyword work while the () cast does not.

    - by Mausimo
    //always works, returning a valid object into _page _page = _httpContext.Handler as System.Web.UI.Page; //Fails throwing the exception : Unable to cast object of type 'System.Web.DefaultHttpHandler' to type 'System.Web.UI.Page' _page = (System.Web.UI.Page)_httpContext.Handler; I would like to know why this happens?

    Read the article

  • Does the Visual Studio debugger implicitly cast smaller types to int?

    - by emddudley
    Does the Visual Studio 2008 debugger implicitly cast all smaller data types to int? I have a function with the following signature: public int DoSomething(sbyte value) { ... } When pass in -127 and I look at the value argument the Visual Studio debugger (e.g. Watch window) shows me that it has the value 0xFFFFFF81. This is correct except for the fact that sbyte is only 8 bits wide; I would expect the debugger to show me that it is 0x81.

    Read the article

  • Is it OK to use dynamic typing to reduce the amount of variables in scope?

    - by missingno
    Often, when I am initializing something I have to use a temporary variable, for example: file_str = "path/to/file" file_file = open(file) or regexp_parts = ['foo', 'bar'] regexp = new RegExp( regexp_parts.join('|') ) However, I like to reduce the scope my variables to the smallest scope possible so there is less places where they can be (mis-)used. For example, I try to use for(var i ...) in C++ so the loop variable is confined to the loop body. In these initialization cases, if I am using a dynamic language, I am then often tempted to reuse the same variable in order to prevent the initial (and now useless) value from being used latter in the function. file = "path/to/file" file = open(file) regexp = ['...', '...'] regexp = new RegExp( regexp.join('|') ) The idea is that by reducing the number of variables in scope I reduce the chances to misuse them. However this sometimes makes the variable names look a little weird, as in the first example, where "file" refers to a "filename". I think perhaps this would be a non issue if I could use non-nested scopes begin scope1 filename = ... begin scope2 file = open(filename) end scope1 //use file here //can't use filename on accident end scope2 but I can't think of any programming language that supports this. What rules of thumb should I use in this situation? When is it best to reuse the variable? When is it best to create an extra variable? What other ways do we solve this scope problem?

    Read the article

  • What is the point of dynamic allocation in C++?

    - by Aerovistae
    I really have never understood it at all. I can do it, but I just don't get why I would want to. For instance, I was programming a game yesterday, and I set up an array of pointers to dynamically allocated little enemies in the game, then passed it to a function which updates their positions. When I ran the game, I got one of those nondescript assertion errors, something about a memory block not existing, I don't know. It was a run-time error, so it didn't say where the problem was. So I just said screw it and rewrote it with static instantiation, i.e.: while(n<4) { Enemy tempEnemy = Enemy(3, 4); enemyVector.push_back(tempEnemy); n++; } updatePositions(&enemyVector); And it immediately worked perfectly. Now sure, some of you may be thinking something to the effect of "Maybe if you knew what you were doing," or perhaps "n00b can't use pointers L0L," but frankly, you really can't deny that they make things way overcomplicated, hence most modern languages have done away with them entirely. But please-- someone -- What IS the point of dynamic allocation? What advantage does it afford? Why would I ever not do what I just did in the above example?

    Read the article

  • GCC, -O2, and bitfields - is this a bug or a feature?

    - by Rooke
    Today I discovered alarming behavior when experimenting with bit fields. For the sake of discussion and simplicity, here's an example program: #include <stdio.h> struct Node { int a:16 __attribute__ ((packed)); int b:16 __attribute__ ((packed)); unsigned int c:27 __attribute__ ((packed)); unsigned int d:3 __attribute__ ((packed)); unsigned int e:2 __attribute__ ((packed)); }; int main (int argc, char *argv[]) { Node n; n.a = 12345; n.b = -23456; n.c = 0x7ffffff; n.d = 0x7; n.e = 0x3; printf("3-bit field cast to int: %d\n",(int)n.d); n.d++; printf("3-bit field cast to int: %d\n",(int)n.d); } The program is purposely causing the 3-bit bit-field to overflow. Here's the (correct) output when compiled using "g++ -O0": 3-bit field cast to int: 7 3-bit field cast to int: 0 Here's the output when compiled using "g++ -O2" (and -O3): 3-bit field cast to int: 7 3-bit field cast to int: 8 Checking the assembly of the latter example, I found this: movl $7, %esi movl $.LC1, %edi xorl %eax, %eax call printf movl $8, %esi movl $.LC1, %edi xorl %eax, %eax call printf xorl %eax, %eax addq $8, %rsp The optimizations have just inserted "8", assuming 7+1=8 when in fact the number overflows and is zero. Fortunately the code I care about doesn't overflow as far as I know, but this situation scares me - is this a known bug, a feature, or is this expected behavior? When can I expect gcc to be right about this? Edit (re: signed/unsigned) : It's being treated as unsigned because it's declared as unsigned. Declaring it as int you get the output (with O0): 3-bit field cast to int: -1 3-bit field cast to int: 0 An even funnier thing happens with -O2 in this case: 3-bit field cast to int: 7 3-bit field cast to int: 8 I admit that attribute is a fishy thing to use; in this case it's a difference in optimization settings I'm concerned about.

    Read the article

  • Is it possible to generate dynamic proxy for static class or static method in C#?

    - by Jeffrey
    I am trying to come up with a way that (either static or instance) method calls can be intercepted by dynamic proxy. I want to implement it as c# extension methods but stuck on how to generate dynamic proxy for static methods. Some usages: Repository.GetAll<T>().CacheForMinutes(10); Repository.GetAll<T>().LogWhenErrorOccurs(); //or var repo = new Repository(); repo.GetAll<T>().CacheForMinutes(10); repo.GetAll<T>().LogWhenErrorOccurs(); I am open to any library (linfu, castle.dynamic proxy 2 or etc). Thanks!

    Read the article

  • Oracle Apex:Why is this dynamic action not getting triggered/fired ?

    - by Sathya
    I'm using Application Express 4.0.0.00.25 ( Apex 4.0 EA2 ). I've created a tabular form, with few fields. Each of the field are not direct entry, but rather a LOV picker is attached to these, and on selecting the LOV value, the id gets stored in the field. I have a dynamic action associated to the field, ( event - change in item, condition - always, action - Set value via SQL query ). However, on selecting the value from the LOV, the dynamic action doesn't get triggered. If I select the dynamic action to be fired on page load, then it works but not upon selection of an item from the LOV. Why is this so, is it by design or a bug ?

    Read the article

  • What's the official Microsoft way to track counts of dynamic controls to be reconstructed upon Postback?

    - by John K
    When creating dynamic controls based on a data source of arbitrary and changing size, what is the official way to track exactly how many controls need to be rebuilt into the page's control collection after a Postback operation (i.e. on the server side during the ASP.NET page event lifecycle) specifically the point at which dynamic controls are supposed to be rebuilt? Where is the arity stored for retrieval and reconstruction usage? By "official" I mean the Microsoft way of doing it. There exist hacks like Session storage, etc but I want to know the bonafide or at least Microsoft-recommended way. I've been unable to find a documentation page stating this information. Usually code samples work with a set of dynamic controls of known numbers. It's as if doing otherwise would be tougher. Update: I'm not inquiring about user controls or static expression of declarative controls, but instead about dynamically injecting controls completely from code-behind, whether they be mine, 3rd-party or built-in ASP.NET controls.

    Read the article

  • How to change "Dynamic Web Project" default source and output folders in Eclipse?

    - by Leslie Norman
    How can I change default values of "source folders on build path" and "default output folder" in "Dynamic Web Project" wizard in Eclipse, probably in the way as we do for "Java Project" in Windows Preferences Java Build Path The purpose is: each time I create new Dynamic Web Project, the wizard should show default source and output folders of my choice. Since this option is available for Java project so I believe there should be something similar for Web Projects too but I am unable to find it. BTW I tried changing defaults of Java project but it does not effect dynamic web projects.

    Read the article

  • Is it a bad idea to use the new Dynamic Keyword as a replacement switch statement?

    - by WeNeedAnswers
    I like the new Dynamic keyword and read that it can be used as a replacement visitor pattern. It makes the code more declarative which I prefer. Is it a good idea though to replace all instances of switch on 'Type' with a class that implements dynamic dispatch. class VistorTest { public string DynamicVisit(object obj) { return Visit((dynamic)obj); } private string Visit(string str) { return "a string was called with value " + str; } private string Visit(int value) { return "an int was called with value " + value; } }

    Read the article

  • Has Object in VB 2010 received the same optimalization as dynamic in C# 4.0?

    - by Abel
    Some people have argued that the C# 4.0 feature introduced with the dynamic keyword is the same as the "everything is an Object" feature of VB. However, any call on a dynamic variable will be translated into a delegate once and from then on, the delegate will be called. In VB, when using Object, no caching is applied and each call on a non-typed method involves a whole lot of under-the-hood reflection, sometimes totaling a whopping 400-fold performance penalty. Have the dynamic type delegate-optimization and caching also been added to the VB untyped method calls, or is VB's untyped Object still so slow?

    Read the article

  • How to enable indexing of pages with dynamic data?

    - by mithunb
    I have a site that has certain urls that point to pages with permanent data and others that point to dynamic web pages. Google indexes both these regularly. By the time a user finds one of the dynamic content urls, the data on the page has already changed and the user does not find what he was looking for. Further, the dynamic url pages contains links to the permanent urls (which I want Google or any crawler to index). Google crawler controls (webmaster tools) cannot be made to read urls from a page but not index them. Solutions? crawling strategies *system architecture*.

    Read the article

  • My (C:) drive changed from Basic to Dynamic, is this bad?

    - by bbman225
    I'm really worried here. My computer still runs, so I take this as a good sign, however let me explain my situation: I am trying to install Ubuntu Linux, and the installer was having problems, so I went back into the partitioning tool on my Windows 7 (after having successfully shrunken my C drive and created 55 GB unallocated space) and I attempted to create a new partition out of the 55 GB and make it a simple NTFS drive so that I could let the installer wipe it clean again and format it in whatever file system it prefers. Now, after googling it and running through the process I noticed that all of my drives, including the C drive and the one I just made changed from type "Basic" to type "Dynamic." What is a dynamic drive and should I be worried?

    Read the article

  • What is the correct way to use g_signal_connect() in C++ for dynamic unity quicklists?

    - by hakermania
    I want to make my application use dynamic unity quicklists. For building my application I am using C++ and the QtCreator IDE. When a menu action is triggered I want to be able to have access to a non-static function of my MainWindow class so as to be able to update the Graphical User Interface which can be accessed from inside 'normal' MainWindow's functions. So, I am building up my quicklist like this (mainwindow.cpp): void MainWindow::enable_unity_quicklist(){ Unity_Menu = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set_bool (Unity_Menu, DBUSMENU_MENUITEM_PROP_VISIBLE, FALSE); Unity_Stop = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(Unity_Stop, DBUSMENU_MENUITEM_PROP_LABEL, "Stop"); dbusmenu_menuitem_child_append (Unity_Menu, Unity_Stop); g_signal_connect (Unity_Stop, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(&fake_callback), (gpointer)this); if(!unity_entry) unity_entry = unity_launcher_entry_get_for_desktop_id("myapp.desktop"); unity_launcher_entry_set_quicklist(unity_entry, Unity_Menu); dbusmenu_menuitem_property_set_bool(Unity_Menu, DBUSMENU_MENUITEM_PROP_VISIBLE, true); dbusmenu_menuitem_property_set_bool(Unity_Stop, DBUSMENU_MENUITEM_PROP_VISIBLE, true); } void MainWindow::fake_callback(gpointer data){ MainWindow* m = (MainWindow*)data; m->on_stopButton_clicked(); } void MainWindow::on_stopButton_clicked(){ //stopping the process... } mainwindow.h: private slots: void enable_unity_quicklist(); void on_stopButton_clicked(); public slots: static void fake_callback(gpointer data); This suggestion was taken from http://old.nabble.com/Using-g_signal_connect-in-class-td18461823.html The program crashes immediately after I choose the 'Stop' action from the Unity Quicklist. Debugging the program shows that I am not able to access anything MainWindow related inside the on_stopButton_clicked() without crashing. For example, it crashes when doing this check (which is the first 2 lines of code inside this function): if (!ui->stopButton->isEnabled()) return; I have also tested lots of other things that I found at the internet, but nothing of them worked. One interesting solution would be to use gtkmm (http://developer.gnome.org/gtkmm-tutorial/stable/sec-connecting-signal-handlers.html.en) but I am not used at all working on GTK applications (I work solely in Qt) and I don't know if this even suits to my occasion. A compilable example indicating what the problem is can be found at: http://ubuntuone.com/7iKA3wnPmWVp8YNNDLlVQI (3.2Kb) If you are not familiar with the QtCreator IDE, you can compile with the following commands, as long as you have all the needed libraries: cd dynamic_unity_quicklists_test; qmake -project; qmake; make

    Read the article

  • IBatis: "Unable to cast object of type 'Castle.Proxies.IDaoProxy' to type 'SysProt.Dao.ICustomerDao'."

    - by j_maly
    I am trying to set up IBatis.NET. I have downloaded the sources from http://mybatisnet.googlecode.com/svn/branches/ibatis-1-maintenance/src. This is my initialization DomDaoManagerBuilder builder = new DomDaoManagerBuilder(); builder.Configure("dao.config"); IDaoManager daoManager = DaoManager.GetInstance("SqlMapDao"); customerDao = daoManager[typeof(ICustomerDao)]; ICustomerDao cd = (ICustomerDao) customerDao; The last line throws InvalidCastException "Unable to cast object of type 'Castle.Proxies.IDaoProxy' to type 'SysProt.Dao.ICustomerDao'." I am not sure, what I did wrong, my dao.config files contains Here are the definitions of the classes/interfaces: public interface ICustomerDao { Customer Load(long id); } public class CustomerDao: BaseDao, ICustomerDao { public Customer Load(long id) { throw new NotImplementedException(); } } public class BaseDao : IDao { protected DaoSession GetContext() { IDaoManager daoManager = DaoManager.GetInstance(this); return (daoManager.LocalDaoSession as DaoSession); } }

    Read the article

  • How to make safe cast using generics in C#?

    - by TN
    I want to implement a generic method on a generic class which would allow to cast safely, see example: public class Foo<T> : IEnumerable<T> { ... public IEnumerable<R> SafeCast<R>() where T : R { return this.Select(item => (R)item); } } However, the compiler tells me that Foo<T>.SafeCast<R>() does not define parameter 'T'. I understand this message that I cannot specify a constraint on T in the method since it is not defined in the method. But how can I specify an inverse constraint?

    Read the article

< Previous Page | 100 101 102 103 104 105 106 107 108 109 110 111  | Next Page >