Search Results

Search found 32346 results on 1294 pages for 'method overloading'.

Page 8/1294 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • creating and returning an array from a method

    - by Troy
    howdy, i currently have a method that checks what is around the centre item in a 3x3 grid, if what is in the 8 adjacent positions is containing what i am checking for i want to mark that square on an array with length 7 as being 1. to do this i need to create and return an array in my method, is it possible to do this?

    Read the article

  • Using "prevent execution of method" flags

    - by tpaksu
    First of all I want to point out my concern with some pseudocode (I think you'll understand better) Assume you have a global debug flag, or class variable named "debug", class a : var debug = FALSE and you use it to enable debug methods. There are two types of usage it as I know: first in a method : method a : if debug then call method b; method b : second in the method itself: method a : call method b; method b : if not debug exit And I want to know, is there any File IO or stack pointer wise difference between these two approaches. Which usage is better, safer and why?

    Read the article

  • JUnit Easymock Unexpected method call

    - by Lancelot
    Hi, I'm trying to setup a test in JUnit w/ EasyMock and I'm running into a small issue that I can't seem to wrap my head around. I was hoping someone here could help. Here is a simplified version of the method I'm trying to test: public void myMethod() { //Some code executing here Obj myObj = this.service.getObj(param); if (myObj.getExtId() != null) { OtherObj otherObj = new OtherObj(); otherObj.setId(myObj.getExtId()); this.dao.insert(otherObj); } //Some code executing there } Ok so using EasyMock I've mocked the service.getObj(myObj) call and that works fine. My problem comes when JUnit hits the dao.insert(otherObj) call. EasyMock throws a "Unexpected Method Call" on it. I wouldn't mind mocking that dao in my test and using expectLastCall().once(); on it, but that assumes that I have a handle on the "otherObj" that's passed as a parameter at insert time... Which of course I don't since it's conditionally created within the context of the method being tested. Anyone has ever had to deal with that and somehow solved it? Thanks.

    Read the article

  • Abstract Methods in "Product" - Factory Method C#

    - by Regina Foo
    I have a simple class library (COM+ service) written in C# to consume 5 web services: Add, Minus, Divide, Multiply and Compare. I've created the abstract product and abstract factory classes. The abstract product named WS's code: public abstract class WS { public abstract double Calculate(double a, double b); public abstract string Compare(double a, double b); } As you see, when one of the subclasses inherits WS, both methods must be overridden which might not be useful in some subclasses. E.g. Compare doesn't need Calculate() method. To instantiate a new CompareWS object, the client class will call the CreateWS() method which returns a WS object type. public class CompareWSFactory : WSFactory { public override WS CreateWS() { return new CompareWS(); } } But if Compare() is not defined as abstract in WS, the Compare() method cannot be invoked. This is only an example with two methods, but what if there are more methods? Is it stupid to define all the methods as abstract in the WS class? My question is: I want to define abstract methods that are common to all subclasses of WS whereas when the factory creates a WS object type, all the methods of the subclasses can be invoked (overridden methods of WS and also the methods in subclasses). How should I do this?

    Read the article

  • Rails does not display error messages on a form in a custom method

    - by slythic
    Hi all, I've created a custom method called checkout in my app. I create an order (which is done my adding products to my "cart"), assign it to my client, and then I head to my checkout screen where I confirm the items and enter their customer order number and complete the order (submit). Everything works great except that it doesn't display error messages. I'm able to display a flash error notice (seen in complete_order method) when things go wrong but it doesn't specify the details like a normal form would. The error messages should appear if the customer order number is not unique for that client. Below is the custom method (checkout) related code. Order Model: validates_uniqueness_of :customer_order_number, :scope => :client_id Orders_controller: def checkout @order = current_order end def complete_order @order = current_order respond_to do |format| if @order.update_attributes(params[:order]) @order.complete #sets submitted datetime and state to 'complete' flash[:notice] = 'Thank you! Your order is being processed.' format.html { redirect_to( products_path ) } format.xml { head :ok } else flash[:error] = 'Please review your items' #added to confirm an error is present format.html { redirect_to( checkout_path ) } format.xml { render :xml => @order.errors, :status => :unprocessable_entity } end end end And the form in the checkout view: <% form_for @order, :url => { :controller => "orders", :action => "complete_order" } do |f| %> <%= f.error_messages %> <%= f.text_field :customer_order_number, :label => "Purchase Order Number" %> <p> <%= f.submit 'Complete Order', :confirm => 'Are you sure?' %> <small> or <%= link_to 'cancel', current_cart_path %></small> </p> <% end %> Any idea how I can display the specific error messages? Thank you in advance! -Tony

    Read the article

  • Calling a method at a specific interval rate in C++

    - by Aetius
    This is really annoying me as I have done it before, about a year ago and I cannot for the life of me remember what library it was. Basically, the problem is that I want to be able to call a method a certain number of times or for a certain period of time at a specified interval. One example would be I would like to call a method "x" starting from now, 10 times, once every 0.5 seconds. Alternatively, call method "x" starting from now, 10 times, until 5 seconds have passed. Now I thought I used a boost library for this functionality but I can't seem to find it now and feeling a bit annoyed. Unfortunately I can't look at the code again as I'm not in possession of it any more. Alternatively, I could have dreamt this all up and it could have been proprietary code. Assuming there is nothing out there that does what I would like, what is currently the best way of producing this behaviour? It would need to be high-resolution, up to a millisecond. It doesn't matter if it blocks the thread that it is executed from or not. Thanks!

    Read the article

  • Is Polymorphism and Method Overloading is almost the same thing in C++

    - by Maxood
    In C++, there are 2 types of Polymorphism: Object Polymorphism Function Polymorphism Function polymorphism is exactly the same thing as method or function overloading i.e. We use the same method names with different parameters and return types. Now the question is why do we have this fancy name Polymorphism in OOP? What distinctly distinguishes polymorphism from method overloading? Can someone explain with a scenario. Thanks

    Read the article

  • How can I call a method given only its name?

    - by mfolnovich
    I'm trying to have method void run( string method ) which would run method in that class. For example: class Foo { public: void run( string method ) { // this method calls method *method* from this class } void bar() { printf( "Function bar\n" ); } void foo2() { printf( "Function foo2\n" ); } } Foo foo; int main( void ) { foo.run( "bar" ); foo.run( "foo2" ); } this would print: Function bar Function foo2 Thanks! :)

    Read the article

  • asp.net detailsview update method not getting new values

    - by Ali
    Hi all, I am binding a detailsview with objectdatasource which gets the select parameter from the querystring. The detailsview shows the desired record, but when I try to update it, my update method gets the old values for the record (and hence no update). here is my detailsview code: <asp:DetailsView ID="dvUsers" runat="server" Height="50px" Width="125px" AutoGenerateRows="False" DataSourceID="odsUserDetails" onitemupdating="dvUsers_ItemUpdating"> <Fields> <asp:CommandField ShowEditButton="True" /> <asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" ReadOnly="true" /> <asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" /> <asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" /> <asp:BoundField DataField="Email" runat="server" HeaderText="Email" SortExpression="Email" /> <asp:BoundField DataField="IsActive" HeaderText="Is Active" SortExpression="IsActive" /> <asp:BoundField DataField="IsOnline" HeaderText="Is Online" SortExpression="IsOnline" ReadOnly="true" /> <asp:BoundField DataField="LastLoginDate" HeaderText="Last Login" SortExpression="LastLoginDate" ReadOnly="true" /> <asp:BoundField DataField="CreateDate" HeaderText="Member Since" SortExpression="CreateDate" ReadOnly="true" /> <asp:TemplateField HeaderText="Membership Ends" SortExpression="ExpiryDate"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ExpiryDate") %>'></asp:TextBox> <cc1:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" Enabled="True" TargetControlID="TextBox1"> </cc1:CalendarExtender> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ExpiryDate") %>'></asp:TextBox> </InsertItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("ExpiryDate") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Fields> and here is the objectdatasource code: <asp:ObjectDataSource ID="odsUserDetails" runat="server" SelectMethod="GetAllUserDetailsByUserId" TypeName="QMS_BLL.Membership" UpdateMethod="UpdateUserForClient"> <UpdateParameters> <asp:Parameter Name="User_ID" Type="Int32" /> <asp:Parameter Name="firstName" Type="String" /> <asp:Parameter Name="lastName" Type="String" /> <asp:SessionParameter Name="updatedByUser" SessionField="userId" DefaultValue="1" /> <asp:Parameter Name="expiryDate" Type="DateTime" /> <asp:Parameter Name="Email" Type="String" /> <asp:Parameter Name="isActive" Type="String" /> </UpdateParameters> <SelectParameters> <asp:QueryStringParameter DefaultValue="1" Name="User_ID" QueryStringField="User_ID" Type="Int32" /> </SelectParameters> </asp:ObjectDataSource> Is the OnItemUpdating method still required when you have your custom BLL method called on insertevent? (which is being executed fine in my case but updating with the old values) or am I missing something else? Also I tried to provide an OnItemUpdating method and in there I tried to capture the contents of the textboxes (the new values). I got an exception: "Specified argument was out of the range of valid values. Parameter name: index" when I tried to do: TextBox txtFirstName = (TextBox)dvUsers.Rows[1].Cells[1].Controls[0]; Any help will be most appreciated.

    Read the article

  • How to prevent duplicate data access methods that retrieve similar data?

    - by Ronald Wildenberg
    In almost every project I work on with a team, the same problem seems to creep in. Someone writes UI code that needs data and writes a data access method: AssetDto GetAssetById(int assetId) A week later someone else is working on another part of the application and also needs an AssetDto but now including 'approvers' and writes the following: AssetDto GetAssetWithApproversById(int assetId) A month later someone needs an asset but now including the 'questions' (or the 'owners' or the 'running requests', etc): AssetDto GetAssetWithQuestionsById(int assetId) AssetDto GetAssetWithOwnersById(int assetId) AssetDto GetAssetWithRunningRequestsById(int assetId) And it gets even worse when methods like GetAssetWithOwnerAndQuestionsById start to appear. You see the pattern that emerges: an object is attached to a large object graph and you need different parts of this graph in different locations. Of course, I'd like to prevent having a large number of methods that do almost the same. Is it simply a matter of team discipline or is there some pattern I can use to prevent this? In some cases it might make sense to have separate methods, i.e. getting an asset with running requests may be expensive so I do not want to include these all the time. How to handle such cases?

    Read the article

  • Does Java support dynamic method invocation?

    - by eSKay
    class A { void F() { System.out.println("a"); }} class B extends A { void F() { System.out.println("b"); }} public class X { public static void main(String[] args) { A objA = new B(); objA.F(); } } Here, F() is being invoked dynamically, isn't it? This article says ... the Java bytecode doesn’t support dynamic method invocation. There are three supported invocations modes : invokestatic, invokespecial, invokeinterface or invokevirtual. These modes allows to call methods with known signature. We talk of strongly typed language. This allows to to make some checks directly at compile time. On the other side, the dynamic languages use dynamic types. So we can call a method unknown at the compile time, but that’s completely impossible with the Java bytecode. What am I missing?

    Read the article

  • Java and junit: derivative of polynomial method testing issue

    - by Curtis
    Hello all, im trying to finish up my junit testing for finding the derivative of a polynomial method and im having some trouble making it work. here is the method: public Polynomial derivative() { MyDouble a = new MyDouble(0); MyDouble b = this.a.add(this.a); MyDouble c = this.b; Polynomial poly = new Polynomial (a, b, c); return poly; } and here is the junit test: public void testDerivative() { MyDouble a = new MyDouble(2), b = new MyDouble(4), c = new MyDouble(8); MyDouble d = new MyDouble(0), e = new MyDouble(4), f = new MyDouble(4); Polynomial p1 = new Polynomial(a, b, c); Polynomial p2 = new Polynomial(d,e,f); assertTrue(p1.derivative().equals(p2)); } im not too sure why it isnt working...ive gone over it again and again and i know im missing something. thank you all for any help given, appreciate it

    Read the article

  • How to find minimum of nonlinear, multivariate function using Newton's method (code not linear algeb

    - by Norman Ramsey
    I'm trying to do some parameter estimation and want to choose parameter estimates that minimize the square error in a predicted equation over about 30 variables. If the equation were linear, I would just compute the 30 partial derivatives, set them all to zero, and use a linear-equation solver. But unfortunately the equation is nonlinear and so are its derivatives. If the equation were over a single variable, I would just use Newton's method (also known as Newton-Raphson). The Web is rich in examples and code to implement Newton's method for functions of a single variable. Given that I have about 30 variables, how can I program a numeric solution to this problem using Newton's method? I have the equation in closed form and can compute the first and second derivatives, but I don't know quite how to proceed from there. I have found a large number of treatments on the web, but they quickly get into heavy matrix notation. I've found something moderately helpful on Wikipedia, but I'm having trouble translating it into code. Where I'm worried about breaking down is in the matrix algebra and matrix inversions. I can invert a matrix with a linear-equation solver but I'm worried about getting the right rows and columns, avoiding transposition errors, and so on. To be quite concrete: I want to work with tables mapping variables to their values. I can write a function of such a table that returns the square error given such a table as argument. I can also create functions that return a partial derivative with respect to any given variable. I have a reasonable starting estimate for the values in the table, so I'm not worried about convergence. I'm not sure how to write the loop that uses an estimate (table of value for each variable), the function, and a table of partial-derivative functions to produce a new estimate. That last is what I'd like help with. Any direct help or pointers to good sources will be warmly appreciated. Edit: Since I have the first and second derivatives in closed form, I would like to take advantage of them and avoid more slowly converging methods like simplex searches.

    Read the article

  • Java input method for Virtual Keyboad

    - by shekhar
    Hi, I am facing problem in implementing Input method for Virtual Keyboard, currently I am using robot class for sending input to any application from virtual keyboard. but for that I need to create mapping of key-code and unicode, which is not consistent on different keyboard layout, can I directly pass the UNICODE to any application using Input method without worry about mapping between keycode and unicode. any useful link or sample code will be useful. It is simple Java program which is always on top of any application and work as onscreen keyboard. using a mouse while you press any button (key) of the keyboard, the corresponding character will be typed in the application running below. This is working perfectly for English Alphabets. I am facing problem while I am doing for unicode.

    Read the article

  • Objective-C method implementation nuances

    - by altdotnetgeek
    I have just started to develop for the iPhone and am in the process of learning Objective-C. I have seen some code that implements a method in the @implementation side of a class like this: -(void)myMethod; { // method body } What makes this interesting is that there is no mention of myMethod in the @interface for the class. I tried a sample project with this and when I compile I get a warning from XCode that myMethod may not be seen by the calling code. Can anyone tell me what is going on? Thanks!

    Read the article

  • execute javascript method after completing code behind method ?

    - by James123
    I can execute below callback() method after completion of document.getElementById('btnDownload').click(); .This Click is Code behind method. Now it is executing immediatly. I want wait "Click()" process done then Execute callback(); 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

  • overriding protected internal with protected!

    - by Asad Butt
    This is an extension for this question asked an hour ago. We cannot modify the access modifiers, when overriding a virtual method in derived class. Consider Control class in System.Web.UI namespace public class Control : IComponent, IDisposable,... { protected internal virtual void CreateChildControls() { } . . } Now Consider This public class someClass : System.Web.UI.Control { // This should not compile but it does protected override void CreateChildControls() { } // This should compile but it does not protected internal override void CreateChildControls() { } } can any body explain this ? Thanks

    Read the article

  • C++ method chaining including class constructor

    - by jena
    Hello, I'm trying to implement method chaining in C++, which turns out to be quite easy if the constructor call of a class is a separate statement, e.g: Foo foo; foo.bar().baz(); But as soon as the constructor call becomes part of the method chain, the compiler complains about expecting ";" in place of "." immediately after the constructor call: Foo foo().bar().baz(); I'm wondering now if this is actually possible in C++. Here is my test class: class Foo { public: Foo() { } Foo& bar() { return *this; } Foo& baz() { return *this; } }; I also found an example for "fluent interfaces" in C++ (http://en.wikipedia.org/wiki/Fluent_interface#C.2B.2B) which seems to be exactly what I'm searching for. However, I get the same compiler error for that code. Thanks in advance for any hint. Best, Jean

    Read the article

  • How do I create a dynamic method in PHP?

    - by sandelius
    I'm trying to extend my ActiveRecord class with some dynamic methods. I would like to be able to run this from my controller $user = User::find_by_username(param); $user = User::find_by_email(param); I've read a little about overloading and think that's the key. I'v got a static $_attributes in my AR class and I get the table name by pluralizing my model (User = users) in this case. How do I do this? All models extends the ActiveRecord class.

    Read the article

  • Calling overridden parent method from parent method

    - by Yisroel
    Heres the situation. Component B extends component A and overrides the init method to accept a different parameter. A also has a create method that calls init. If i have an instance of B and i call create, its calling the wrong init - it calls init in B, where i need it to call init in A. I dont want to call super.init() as there may not always be a super. Is there any way to specify to call the init in the parent component?

    Read the article

  • Django: Overriding the save() method: how do I call the delete() method of a child class

    - by Patti
    The setup = I have this class, Transcript: class Transcript(models.Model): body = models.TextField('Body') doPagination = models.BooleanField('Paginate') numPages = models.PositiveIntegerField('Number of Pages') and this class, TranscriptPages(models.Model): class TranscriptPages(models.Model): transcript = models.ForeignKey(Transcript) order = models.PositiveIntegerField('Order') content = models.TextField('Page Content', null=True, blank=True) The Admin behavior I’m trying to create is to let a user populate Transcript.body with the entire contents of a long document and, if they set Transcript.doPagination = True and save the Transcript admin, I will automatically split the body into n Transcript pages. In the admin, TranscriptPages is a StackedInline of the Transcript Admin. To do this I’m overridding Transcript’s save method: def save(self): if self.doPagination: #do stuff super(Transcript, self).save() else: super(Transcript, self).save() The problem = When Transcript.doPagination is True, I want to manually delete all of the TranscriptPages that reference this Transcript so I can then create them again from scratch. So, I thought this would work: #do stuff TranscriptPages.objects.filter(transcript__id=self.id).delete() super(Transcript, self).save() but when I try I get this error: Exception Type: ValidationError Exception Value: [u'Select a valid choice. That choice is not one of the available choices.'] ... and this is the last thing in the stack trace before the exception is raised: .../django/forms/models.py in save_existing_objects pk_value = form.fields[pk_name].clean(raw_pk_value) Other attempts to fix: t = self.transcriptpages_set.all().delete() (where self = Transcript from the save() method) looping over t (above) and deleting each item individually making a post_save signal on TranscriptPages that calls the delete method Any ideas? How does the Admin do it? UPDATE: Every once in a while as I'm playing around with the code I can get a different error (below), but then it just goes away and I can't replicate it again... until the next random time. Exception Type: MultiValueDictKeyError Exception Value: "Key 'transcriptpages_set-0-id' not found in " Exception Location: .../django/utils/datastructures.py in getitem, line 203 and the last lines from the trace: .../django/forms/models.py in _construct_form form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs) .../django/utils/datastructures.py in getitem pk = self.data[pk_key]

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >