Search Results

Search found 37788 results on 1512 pages for 'dynamic method'.

Page 12/1512 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • Cleaning up a dynamic array of Objects in C++

    - by Dr. Monkey
    I'm a bit confused about handling an array of objects in C++, as I can't seem to find information about how they are passed around (reference or value) and how they are stored in an array. I would expect an array of objects to be an array of pointers to that object type, but I haven't found this written anywhere. Would they be pointers, or would the objects themselves be laid out in memory in an array? In the example below, a custom class myClass holds a string (would this make it of variable size, or does the string object hold a pointer to a string and therefore take up a consistent amount of space. I try to create a dynamic array of myClass objects within a myContainer. In the myContainer.addObject() method I attempt to make a bigger array, copy all the objects into it along with a new object, then delete the old one. I'm not at all confident that I'm cleaning up my memory properly with my destructors - what improvements could I make in this area? class myClass { private string myName; public unsigned short myAmount; myClass(string name, unsigned short amount) { myName = name; myAmount = amount; } //Do I need a destructor here? I don't think so because I don't do any // dynamic memory allocation within this class } class myContainer { int numObjects; myClass * myObjects; myContainer() { numObjects = 0; } ~myContainer() { //Is this sufficient? //Or do I need to iterate through myObjects and delete each // individually? delete [] myObjects; } void addObject(string name, unsigned short amount) { myClass newObject = new myClass(name, amount); myClass * tempObjects; tempObjects = new myClass[numObjects+1]; for (int i=0; i<numObjects; i++) tempObjects[i] = myObjects[i]); tempObjects[numObjects] = newObject; numObjects++; delete newObject; //Will this delete all my objects? I think it won't. //I'm just trying to delete the old array, and have the new array hold // all the objects plus the new object. delete [] myObjects; myObjects = tempObjects; } }

    Read the article

  • ASP.NET Dynamic Data Browser Compatibility

    - by Petras
    Could any experienced users of Dynamic Data comment on whether there are issues with it in: Internet Explorer 6 Safari Chrome Opera We are looking to use it on a public facing website and good old IE6 has many important users in government departments and large companies so it has to work there. The other browsers could also become an issue.

    Read the article

  • Per instance dynamic fields django model

    - by Roberto Rosario
    I have a model with a JSON field or a link to a CouchDB document. I can currently access the dynamic informaction in a way such as: genericdocument.objects.get(pk=1) == genericdocument.json_field['sample subfield'] instead I would like genericdocument.sample_subfield to maintain compatibility with all the apps the project currently shares.

    Read the article

  • Is there an easy way to merge C# dynamic objects

    - by ajma
    Let's say I have two dynamic objects like this: var objA = new { test = "test", blah = "blah" }; var objB = new { foo = "foo", bar = "bar" }; I want to combine them to get: new { test = "test", blah = "blah", foo = "foo", bar = "bar" }; I won't know what the properties are for both objA and objB at compile time. I want this to be like jquery's extend method. Anybody know of a library or a .net framework class that can help me do this?

    Read the article

  • OpenCL C/C++ dynamic binding library (win32 and more)

    - by rotoglup
    I'm giving a try at OpenCL, and in order to put this in production I'd like to be able to bind dynamically to OpenCL.DLL (when under Windows), in order to handle 'gracefully' the case where no OpenCL is installed on the host computer. Is there any available library (or code snippet) that takes care of this dynamic binding in C or C++, much like GLEW does for OpenGL ? I'd like to avoid the hassle to do it myself. Thanks,

    Read the article

  • Dynamic Data - Make Friendly Column Names?

    - by davemackey
    I've created a Dynamic Data project with an Entity Framework model. It works nicely. But, right now it shows all my database tables with the db column names - which aren't always the most friendly (e.g. address_line_1). How can I got about giving these more friendly column titles that will display to the end user?

    Read the article

  • How to name a static factory method in the utility class?

    - by leventov
    I have an interface MyLongNameInterface with a counterpart utility class MyLongNameInterfaces. What is the best name for a static factory method in the utility class, which creates an instance of MyLongNameInterface? MyLongNameInterfaces.newInstance() -- a new instance of the utility class? MyLongNameInterfaces.newMyLongNameInterface() -- too verbose MyLongNameInterfaces.create() -- create an instance of the utility class? Also, create is not a widely used conventional verb in Java better option?

    Read the article

  • call a class method from inside an instance method from a module mixin (rails)

    - by sean
    Curious how one would go about calling a class method from inside an instance method of a module which is included by an active record class. For example I want both user and client models to share the nuts and bolts of password encryption. # app/models class User < ActiveRecord::Base include Encrypt end class Client < ActiveRecord::Base include Encrypt end # app/models/shared/encrypt.rb module Encrypt def authenticate # I want to call the ClassMethods#encrypt_password method when @user.authenticate is run self.password_crypted == self.encrypt_password(self.password) end def self.included(base) base.extend ClassMethods end module ClassMethods def encrypt_password(password) Digest::SHA1.hexdigest(password) end end end However, this fails. Says that the class method cannot be found when the instance method calls it. I can call User.encrypt_password('password') but User.new.encrypt_password fails Any thoughts?

    Read the article

  • Java Finalize method call

    - by Rajesh Kumar J
    I need to find when finalized method called in the JVM. I Created a test Class which write into file when finalized method called by Overriding the protected finalize method It is not executing. Can anybody tell me the reason why it is not executing?? Thanks in Advance

    Read the article

  • ASP.NET lock thread method

    - by Peter
    Hello, I'm developing an ASP.NET forms webapplication using C#. I have a method which creates a new Order for a customer. It looks similar to this; private string CreateOrder(string userName) { // Fetch current order Order order = FetchOrder(userName); if (order.OrderId == 0) { // Has no order yet, create a new one order.OrderNumber = Utility.GenerateOrderNumber(); order.Save(); } return order; } The problem here is, it is possible that 1 customer in two requests (threads) could cause this method to be called twice while another thread is also inside this method. This can cause two orders to be created. How can I properly lock this method, so it can only be executed by one thread at a time per customer? I tried; Mutex mutex = null; private string CreateOrder(string userName) { if (mutex == null) { mutex = new Mutex(true, userName); } mutex.WaitOne(); // Code from above mutex.ReleaseMutex(); mutex = null; return order; } This works, but on some occasions it hangs on WaitOne and I don't know why. Is there an error, or should I use another method to lock? Thanks

    Read the article

  • custom compare method in objective c

    - by Jonathan
    I'm trying to use a custom compare method (for use with sortedArrayusingSelector) and on another website I got that the format is: -(NSComparisonResult) orderByName:(id)otherobject { That's all bery well and good except how do I compare the otherObject to anything as there's only one thing passed to the method? Like how does the NSString method of compare: compare 2 strings when only one string is passed?

    Read the article

  • Partial overriding in Java (or dynamic overriding while overloading)

    - by Lie Ryan
    If I have a parent-child that defines some method .foo() like this: class Parent { public void foo(Parent arg) { System.out.println("foo in Function"); } } class Child extends Parent { public void foo(Child arg) { System.out.println("foo in ChildFunction"); } } When I called them like this: Child f = new Child(); Parent g = f; f.foo(new Parent()); f.foo(new Child()); g.foo(new Parent()); g.foo(new Child()); the output is: foo in Parent foo in Child foo in Parent foo in Parent But, I want this output: foo in Parent foo in Child foo in Parent foo in Child I have a Child class that extends Parent class. In the Child class, I want to "partially override" the Parent's foo(), that is, if the argument arg's type is Child then Child's foo() is called instead of Parent's foo(). That works Ok when I called f.foo(...) as a Child; but if I refer to it from its Parent alias like in g.foo(...) then the Parent's foo(..) get called irrespective of the type of arg. As I understand it, what I'm expecting doesn't happen because method overloading in Java is early binding (i.e. resolved statically at compile time) while method overriding is late binding (i.e. resolved dynamically at compile time) and since I defined a function with a technically different argument type, I'm technically overloading the Parent's class definition with a distinct definition, not overriding it. But what I want to do is conceptually "partially overriding" when .foo()'s argument is a subclass of the parent's foo()'s argument. I know I can define a bucket override foo(Parent arg) in Child that checks whether arg's actual type is Parent or Child and pass it properly, but if I have twenty Child, that would be lots of duplication of type-unsafe code. In my actual code, Parent is an abstract class named "Function" that simply throws NotImplementedException(). The children includes "Polynomial", "Logarithmic", etc and .foo() includes things like Child.add(Child), Child.intersectionsWith(Child), etc. Not all combination of Child.foo(OtherChild) are solvable and in fact not even all Child.foo(Child) is solvable. So I'm best left with defining everything undefined (i.e. throwing NotImplementedException) then defines only those that can be defined. So the question is: Is there any way to override only part the parent's foo()? Or is there a better way to do what I want to do?

    Read the article

  • Dynamic adding of usercontrols not showing control on page

    - by Phil
    I am trying to insert a user control dynamically into my default.aspx page via the following method in the page_init: Dim control As UserControl = LoadControl("~\Modules\Content.ascx") Controls.Add(control) When I run the page there is no sign of the usercontrol. Am I using the correct code to insert the usercontrol? Is there an alternative method of insertion available? Does the fact that the usercontrol has a page_load make a difference? Do I need to register the control in my aspx page at design time? Thanks in advance for any assistance you can offer.

    Read the article

  • groovy call private method in Java super class

    - by Jeff Storey
    I have an abstract Java class MyAbstractClass with a private method. There is a concrete implementation MyConcreteClass. public class MyAbstractClass { private void somePrivateMethod(); } public class MyConcreteClass extends MyAbstractClass { // implementation details } In my groovy test class I have class MyAbstractClassTest { void myTestMethod() { MyAbstractClass mac = new MyConcreteClass() mac.somePrivateMethod() } } I get an error that there is no such method signature for somePrivateMethod. I know groovy can call private methods but I'm guessing the problem is that the private method is in the super class, not MyConcreteClass. Is there a way to invoke a private method in the super class like this (other than using something like PrivateAccessor)? thanks Jeff

    Read the article

  • Ruby: Add a method to the class of an input parameter

    - by TJB
    I'm just exploring ruby and was wondering about the theoretical possibility of adding a method to the class of an object. For example, define a method that takes in a parameter and would add a method to the class of that parameter (not just to the parameter object itself). Something like this example: class SomeClass end class AnotherClass end alpha = SomeClass.new beta = AnotherClass.new def AddHelloMethodTo param # This is where I'm trying to # add a method to the class of the parameter def param.class.Hello "Hello" end end AddHelloMethodTo alpha AddHelloMethodTo beta gamma = AnotherClass.new alpha.Hello beta.Hello gamma.Hello (Excuse me if I have syntax errors / typos I'm REALLY new to this!) Notice how I don't call the AddHelloMethodTo on gamma but I expect Hello to be defined because I added it to the class. Is this possible?

    Read the article

  • Invoke private method with interface as argument

    - by Stephanie
    Hi, I've been attempting to invoke a private method whose argument is a parameter and I can't quite seem to get it right. Here's kind of how the code looks so far: public class TestClass { public TestClass(){ } private void simpleMethod( Map<String, Integer> testMap) { //code logic } } Then I attempt to use this to invoke the private method: //Hashmap Map <String, Integer> testMap = new HashMap <String, Integer>(); //method I want to invoke Method simpleMethod = TestClass.class.getDeclaredMethod("simpleMethod", Map.class); simpleMethod.setAccessible(true); simpleMethod.invoke(testClassObject, testMap); //Throws an IllegalArgumentException As you can see, it throws an IllegalArgumentException. I've attempted to cast the hashmap back to a map, but that didn't work. What am I doing wrong?

    Read the article

  • Can a C# method chain be "too long"?

    - by ccornet
    Not in terms of readability, naturally, since you can always arrange the separate methods into separate lines. Rather, is it dangerous, for any reason, to chain an excessively large number of methods together? I use method chaining primarily to save space on declaring individual one-use variables, and traditionally using return methods instead of methods that modify the caller. Except for string methods, those I kinda chain mercilessly. In any case, I worry sometimes about the impact of using exceptionally long method chains all in one line. Let's say I need to update the value of one item based on someone's username. Unfortunately, the shortest method to retrieve the correct user looks something like the following. SPWeb web = GetWorkflowWeb(); SPList list2 = web.Lists["Wars"]; SPListItem item2 = list2.GetItemById(3); SPListItem item3 = item2.GetItemFromLookup("Armies", "Allied Army"); SPUser user2 = item2.GetSPUser("Commander"); SPUser user3 = user2.GetAssociate("Spouse"); string username2 = user3.Name; item1["Contact"] = username2; Everything with a 2 or 3 lasts for only one call, so I might condense it as the following (which also lets me get rid of a would-be-superfluous 1): SPWeb web = GetWorkflowWeb(); item["Contact"] = web.Lists["Armies"] .GetItemById(3) .GetItemFromLookup("Armies", "Allied Army") .GetSPUser("Commander") .GetAssociate("Spouse") .Name; Admittedly, it looks a lot longer when it is all in one line and when you have int.Parse(ddlArmy.SelectedValue.CutBefore(";#", false)) instead of 3. Nevertheless, this is one of the average lengths of these chains, and I can easily foresee some of exceptionally longer counts. Excluding readability, is there anything I should be worried about for these 10+ method chains? Or is there no harm in using really really long method chains?

    Read the article

  • LINQ method chaining and granular error handling

    - by Clafou
    I have a method which can be written pretty neatly through method chaining: return viewer.ServerReport.GetParameters() .Single(p => p.Name == Convention.Ssrs.RegionParamName) .ValidValues .Select(v => v.Value); However I'd like to be able to do some checks at each point as I wish to provide helpful diagnostics information if any of the chained methods returns unexpected results. To achieve this, I need to break up all my chaining and follow each call with an if block. It makes the code a lot less readable. Ideally I'd like to be able to weave in some chained method calls which would allow me to handle unexpected outcomes at each point (e.g. throw a meaningful exception such as new ConventionException("The report contains no parameter") if the first method returns an empty collection). Can anyone suggest a simple way to achieve such a thing?

    Read the article

  • applet communication using post method

    - by mithun1538
    I have an applet that is communicating with a servlet. I am communicating with the servlet using POST method. My problem is how do I send parameters to the servlet. Using GET method, this is fairly simple ( I just append the parameters to the URL after a ?). But using POST method how do I send the parameters, so that in the servlet side, I can use the statement : message = req.getParameter("msg"); In the applet side, I establish POST method connection as follows : URL url = new URL(getCodeBase(), "servlet"); URLConnection con = url.openConnection(); con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); con.setRequestProperty("Content-Type","application/octet-stream");

    Read the article

  • execute javascript method after method excution complete ?

    - by James123
    I want execute below callback()method after completion of process document.getElementById('btnDownload').click(); method. click() is the code behind method. That means, I mean after complete process of click() then excute callback() method. Because my modelpop is not hiding in code behind. So I want hide in javascript method. function LoadPopup() { // find the popup behavior this._popup = $find('mdlPopup'); // show the popup this._popup.show(); // synchronously run the server side validation ... document.getElementById('btnDownload').click(); callback(); } function callback() { this._popup = $find('mdlPopup'); // hide the popup this._popup.hide(); alert("hi"); }

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >