Search Results

Search found 7418 results on 297 pages for 'argument passing'.

Page 56/297 | < Previous Page | 52 53 54 55 56 57 58 59 60 61 62 63  | Next Page >

  • Passing arguments to objects created using the new operator?

    - by Abhijit
    Hi guys, I have a small C++ problem to which I don't know the best solution. I have two classes A and B as follows: class A { int n; B* b; public: A(int num): n(num) { b = new B[n]; for (int i = 0; i < n; i++) { b[i].setRef(this); } } ~A() { delete [] b; } }; class B { A* a; public: B() { } B(A* aref) { a = aref; } void setRef(A* aref) { a = aref; } }; I am creating an object of class A by passing to its constructor the number of objects of class B I want to be created. I want every object of class B to hold a pointer to the class A object that creates it. I think the best way to do this would be by passing the pointer to the class A object as a constructor argument to the class B object. However, since I'm using the new operator, the no-args constructor for class B is called. As a result, the only solution I can see here is calling the setRef(A*) method for every object of class B after it has been constructed using the new operator. Is there a better solution/design pattern that would be more applicable here? Would using placement new for class B be a better solution? Thanks in advance for your help.

    Read the article

  • Should I pass a SqlDataReader by reference or not when passing it out to multiple threads.

    - by deroby
    Hi all, being new to c# I've run into this 'conundrum' when passing around a SqlDataReader between different threads. Without going into too much detail, the idea is to have a main thread fetching data from the database (a large recordset) and then have a helper-task run through this record by record and doing some stuff based upon the contents of this. There is no feedback to the recordset, it simply wades through until no records are left. This works fine, but given the nature of the job at hand it should be possible to have this job spread over different threads (CPUs) to maximize throughput (the order of execution is of no significance). The question then becomes, when I pass this recordset in a SqlDataReader, do I have to use ref or not ? It kind of boils down to the question : if I pass the object around without specifying ref, won't it create new copies in memory and have records processed n times ? Or, don't I risk having the record-position being moved forward while not all fields have been fully read yet ? The latter seems more like a 'data racing' issue and probably is covered by the lock()ing mechanism (or not?). My initial take on the problem was that it doesn't really hurt passing the variable using ref, yet as a colleague put it : "you only need ref when you're doing something wrong" =) Additionally using ref restricts me from applying a Using() construction too which isn't very nice either. I thus create a "basic" project that tackles the same approach but without the ref notation. Tests so far show that it works flawlessly on a Core2Duo (2cpu) using any number of threads, yet I'm still a bit wary... What do you experts think about this ? Use ref or not ? You can find the test-project here as it seems I can't upload it to this question directly ?!? ps: it's just a test-project and I'm new to c#, so please be gentle on me when breaking down the code =P

    Read the article

  • Ubuntu 10.04 on virtualbox gives error: Target filesystem doesn't have /sbin/init \ No init found. Try passing init= bootarg

    - by Philip
    I'm a linux newbie and the only reason I have it installed is so I can stop having Windows incompatibility issues with Ruby on Rails. Having said that, it sure has been nice, and much faster, and I don't think I'll be doing any Winrails stuff anytime soon. So I created a virtualmachine using virtualbox and have had ubuntu on it for the last 3 weeks. Recently ubuntu asked if it could update a few things, I clicked 'ok'. Now it won't boot and I get this error: *mount: mounting /dev on /root/dev failed: No such file or directory mount: mounting /sys on /root/sys failed: No such file or directory ... Target filesystem doesn't have /sbin/init. No init found. Try passing init= bootarg BusyBox v1.13.3... (initramfs) _ * So I cruised the forums and there are a variety of solutions, but they all have to do with booting from the live cd. (which I assume is the ISO image I used to install ubuntu in the first place). But when I boot from that CD, it just hangs on the ubuntu screen, and the little dots keep cycling white to red, but it hung there for an hour so I think it was stuck. Not sure what I can do; can I do anything from the busybox shell (or whatever that is) to fix things? The thing is, it took about 10 hours to get everything the way I needed with all the gems and whatnot. And I didn't really write down what I tweaked, and I'm middle aged, so all that information has leaked out by now and I don't want to do it again. I'd really like to repair my existing install. One question you might have is, is there something wrong with the ISO? I don't think so, because I made a new virtual machine and used that same iso file to install a fresh ubuntu. Any help much appreciated. Phil

    Read the article

  • Int or NSInteger as object for method argument. Objective-C

    - by sergiobuj
    Hi. I'm having some trouble passing a number as an argument for a method: -(void) meth2:(int)next_int; And to call that method i need this: int next_int = 1; [self performSelectorOnMainThread:@selector(meth2:) withObject:next_int waitUntilDone:NO]; //update next_int and call meth2 again at this point i get a "pointer from integer without a cast" error, and would happen the same with a NSInteger. A NSNumber is not useful because it's immutable and i need to change the value constantly. Any Idea how can i do this? Thanks.

    Read the article

  • implicit argument passing of super from method defined by define_method() is not supported. Specify

    - by jaycode
    Most of you should already know Pragmatic book's "Agile web dev with rails" (third edition). On page 537 - 541 it has "Custom Form Builders" code as follows: class TaggedBuilder < ActionView::Helpers::FormBuilder # <p> # <label for="product_description">Description</label><br/> # <%= form.text_area 'description' %> #</p> def self.create_tagged_field(method_name) define_method(method_name) do |label, *args| @template.content_tag("p" , @template.content_tag("label" , label.to_s.humanize, :for => "#{@object_name}_#{label}") + "<br/>" + super) end end field_helpers.each do |name| create_tagged_field(name) end end This code doesn't work with Ruby 1.9.1. It returns error as follows: implicit argument passing of super from method defined by define_method() is not supported. Specify all arguments explicitly. (ActionView::TemplateError) My question is: What should I change in the code to fix this? Thank you

    Read the article

  • How can I pipe a large amount of data as a runtime argument?

    - by Zombies
    Running an executable JAR on a linux platform here. The program it self works on a somewhat large amount of data, basically a list of URLs... could be up to 2k. Currently I get this from a simple DB call. But I was thinking that instead of creating a new mode and writing SQL to get a new result set and having to redploy everytime, I could just make the program more robust by passing in the result set (the list of URLs) that need to be worked on... so, within a linux environment, is there a pain-free/simple way to get the result set and pass it in dynamically? I know file i/o is one, but it doesn't seem to be effecient because each file has to be named, as well more logic to handle grabbing the correct file, creating a file with a unique name, etc.

    Read the article

  • Designing different Factory classes (and what to use as argument to the factories!)

    - by devoured elysium
    Let's say we have the following piece of code: public class Event { } public class SportEvent1 : Event { } public class SportEvent2 : Event { } public class MedicalEvent1 : Event { } public class MedicalEvent2 : Event { } public interface IEventFactory { bool AcceptsInputString(string inputString); Event CreateEvent(string inputString); } public class EventFactory { private List<IEventFactory> factories = new List<IEventFactory>(); public void AddFactory(IEventFactory factory) { factories.Add(factory); } //I don't see a point in defining a RemoveFactory() so I won't. public Event CreateEvent(string inputString) { try { //iterate through all factories. If one and only one of them accepts //the string, generate the event. Otherwise, throw an exception. return factories.Single(factory => factory.AcceptsInputString(inputString)).CreateEvent(inputString); } catch (InvalidOperationException e) { throw new InvalidOperationException("No valid factory found to generate this kind of Event!", e); } } } public class SportEvent1Factory : IEventFactory { public bool AcceptsInputString(string inputString) { return inputString.StartsWith("SportEvent1"); } public Event CreateEvent(string inputString) { return new SportEvent1(); } } public class MedicalEvent1Factory : IEventFactory { public bool AcceptsInputString(string inputString) { return inputString.StartsWith("MedicalEvent1"); } public Event CreateEvent(string inputString) { return new MedicalEvent1(); } } And here is the code that runs it: static void Main(string[] args) { EventFactory medicalEventFactory = new EventFactory(); medicalEventFactory.AddFactory(new MedicalEvent1Factory()); medicalEventFactory.AddFactory(new MedicalEvent2Factory()); EventFactory sportsEventFactory = new EventFactory(); sportsEventFactory.AddFactory(new SportEvent1Factory()); sportsEventFactory.AddFactory(new SportEvent2Factory()); } I have a couple of questions: Instead of having to add factories here in the main method of my application, should I try to redesign my EventFactory class so it is an abstract factory? It'd be better if I had a way of not having to manually add EventFactories every time I want to use them. So I could just instantiate MedicalFactory and SportsFactory. Should I make a Factory of factories? Maybe that'd be over-engineering? As you have probably noticed, I am using a inputString string as argument to feed the factories. I have an application that lets the user create his own events but also to load/save them from text files. Later, I might want to add other kinds of files, XML, sql connections, whatever. The only way I can think of that would allow me to make this work is having an internal format (I choose a string, as it's easy to understand). How would you make this? I assume this is a recurrent situation, probably most of you know of any other more intelligent approach to this. I am then only looping in the EventFactory for all the factories in its list to check if any of them accepts the input string. If one does, then it asks it to generate the Event. If you find there is something wrong or awkward with the method I'm using to make this happen, I'd be happy to hear about different implementations. Thanks! PS: Although I don't show it in here, all the different kind of events have different properties, so I have to generate them with different arguments (SportEvent1 might have SportName and Duration properties, that have to be put in the inputString as argument).

    Read the article

  • How to fix "Sub-process /usr/bin/dpkg returned an error code (1)" when installing and upgrading packages?

    - by soum
    I am getting this error whenever tring to install or update anything: "Sub-process /usr/bin/dpkg returned an error code (1)" I need help, as I cannot install or upgrade any packages on my Ubuntu 11.10 system. Here is the rest of the error: unknown argument `triggered' dpkg: error processing mtools (--configure): subprocess installed post-installation script returned error exit status 1 Processing triggers for network-manager-pptp-gnome ... No apport report written because MaxReports is reached already postinst called with unknown argument `triggered' dpkg: error processing network-manager-pptp-gnome (--configure): subprocess installed post-installation script returned error exit status 1 No apport report written because MaxReports is reached already Processing triggers for network-manager-pptp ... postinst called with unknown argument `triggered' dpkg: error processing network-manager-pptp (--configure): subprocess installed post-installation script returned error exit status 1 No apport report written because MaxReports is reached already Processing triggers for network-manager-gnome ... /var/lib/dpkg/info/network-manager-gnome.postinst called with unknown argument `triggered' dpkg: error processing network-manager-gnome (--configure): subprocess installed post-installation script returned error exit status 1 Processing triggers for network-manager ... No apport report written because MaxReports is reached already /var/lib/dpkg/info/network-manager.postinst called with unknown argument `triggered' dpkg: error processing network-manager (--configure): subprocess installed post-installation script returned error exit status 1 No apport report written because MaxReports is reached already Processing triggers for mscompress ... postinst called with unknown argument `triggered' dpkg: error processing mscompress (--configure): subprocess installed post-installation script returned error exit status 1 No apport report written because MaxReports is reached already Errors were encountered while processing: netbase mtr-tiny module-init-tools mountmanager mono-4.0-gac mousetweaks mozilla-plugin-vlc mtools network-manager-pptp-gnome network-manager-pptp network-manager-gnome network-manager mscompress E: Sub-process /usr/bin/dpkg returned an error code (1)

    Read the article

  • LINQ, "Argument types do not match" error, what does it mean, how do I address it?

    - by Biff MaGriff
    Hello, I'm new to linq and I'm trying to databind to an anonymous type. I'm using SubSonic 3.0 as my DAL. I'm doing a select from 2 tables like so var myDeal = (from u in db.Users select new { UserID = u.UserID, UserRoleID = (from ur in u.UserRoles where u.UserRoleID == ur.UserRoleID select ur).FirstOrDefault().UserRoleID }); foreach (var v in myDeal) //dies first time here { } Then when I databind or try to iterate through the collection I get the "Argument types do not match" error during run time. I'm not sure what is going on here.

    Read the article

  • How to debug a tcl script which is argument to an executable?

    - by user321047
    I have a application which takes tcl script as argument. I want to debug tcl script when the application processes it. My development environment consists of Dynamic Languages Toolkit from www.eclipse.org/dltk along with Active state remote debugger -dbgp_tcldebug. I am able to debug the individual tcl scripts with this setup. I created a tcl project in eclipse and added 'startup.tcl' and 'argumentScript.tcl' scripts and added following command to the startup script, set ExecutableName "xyz.exe" set returnValue [catch {eval exec $ExecutableName "argumentScript.tcl" } result] My debugger works fine with 'startup.tcl' script. I added the breakpoint in 'argumentScript.tcl' but it is not working. How can I debug the "argumentScript.tcl" script ? Edit: A solution without using eclipse environment is Tcl Dev Kit with remote debugging feature.

    Read the article

  • Do I always have to provide Tkx's -command argument an anonymous subroutine?

    - by Zaid
    I find it a bit weird that I have to wrap defined subroutines anonymously when specifying the -command argument for Tkx widgets. An excerpt from a TkDocs tutorial demonstrates this: my $cb = $frm->new_ttk__button ( -text => "Calculate", -command => sub {calculate();} ); sub calculate { $meters = int(0.3048*$feet*10000.0+.5)/10000.0 || ''; } Why doesn't it work when I write -command => &calculate() or -command => \&calculate()?

    Read the article

  • Do I always have to supply Tkx's -command argument with an anonymous subroutine?

    - by Zaid
    I find it a bit weird that I have to wrap defined subroutines anonymously when specifying the -command argument for Tkx widgets. The example from TkDocs demonstrates this: my $cb = $frm->new_ttk__button ( -text => "Calculate", -command => sub {calculate();} ); sub calculate { $meters = int(0.3048*$feet*10000.0+.5)/10000.0 || ''; } Why doesn't it work when I write -command => &calculate() or -command => \&calculate()?

    Read the article

  • How do I format positional argument help using Python's optparse?

    - by cdleary
    As mentioned in the docs the optparse.OptionParser uses an IndentedHelpFormatter to output the formatted option help, for which which I found some API documentation. I want to display a similarly formatted help text for the required, positional arguments in the usage text. Is there an adapter or a simple usage pattern that can be used for similar positional argument formatting? Clarification Preferably only using the stdlib. Optparse does great except for this one formatting nuance, which I feel like we should be able to fix without importing whole other packages. :-)

    Read the article

  • Why would the first call to a KVC setter have an NSTextField instance as the argument?

    - by Stephen
    If I have a NSTextField bound through an NSObjectController to a model object, I would expect the setter of the model object to be called with an NSString as the argument, but instead, I receive the instance of the control that I am bound too the first time I am called. - (NSString *)property { NSLog(@"returning property"); return property; } - (void)setProperty:(NSString *)string { NSLog(@"recieved %@", string) } - (id) init { if (self = [super init]) { property = [[NSString alloc] initWithString:@"value"]; } NSLog(@"property is %@",property"); return self; } (The program doesn't run if you try anything in setProperty, because it tries to send NSString messages to string - which might be an NSTextField.) Console Output: 2010-05-12 14:19:14.096 Trouble[13108:10b] property is enter value 2010-05-12 14:19:14.100 Trouble[13108:10b] recieved <NSTextField: 0x1025210> 2010-05-12 14:19:14.106 Trouble[13108:10b] returning property

    Read the article

  • In ActionScript, Is there a way to check if an input argument is a valid Vector of any type?

    - by ty
    In the following code: var a:Vector.<int> ... var b:Vector.<String> ... var c:Vector.<uint> ... var c:Vector.<MyOwnClass> ... function verifyArrayLike(arr:*):Boolean { return (arr is Array || arr is Vector) } verifyArrayLike(a); verifyArrayLike(b); ... What I'm looking for is something like _var is Vector.<*> But Vector.<*> is not a valid expression, even Vector. can not be placed at the right side of operators. Is there a way to check if an input argument is a valid Vector of any type?

    Read the article

  • Using C++, how to call a base class method from a derived class method and apply this to an object passed as an argument?

    - by Chris
    I can't figure out how to call a base class method from a derived class method but concurrently applying this method call at an object passed as argument. What I mean is this: class Animal { virtual void eat(Animal& to_be_eaten) = 0; }; class Carnivores: public Animal { virtual void eat(Animal& to_be_eaten) { /*implementation here*/} }; class Wolf : public Carnivores { virtual void eat(Animal& to_be_eaten) { /*call eat method(of Base class) of Base to_be_eaten here*/ } } I thought of something like this dynamic_cast<Carnivores&>(to_be_eaten).eat(*this) //and got a segmentation fault Is there any way for this to be done? Thank you! New edit:: Updated the code

    Read the article

  • Why does C's "fopen" take a "const char *" as its second argument?

    - by Chris Cooper
    It has always struck me as strange that the C function "fopen" takes a "const char *" as the second argument. I would think it would be easier to both read your code and implement the library's code if there were bit masks defined in stdio.h, like "IO_READ" and such, so you could do things like: FILE* myFile = fopen("file.txt", IO_READ & IO_WRITE); Is there a programmatic reason for the way it actually is, or is it just historic? (i.e. "That's just the way it is.")

    Read the article

  • What is Perl doing with this argument to push in this case?

    - by Morinar
    I just saw some code in our code base (and it's OLD code, as in Perl 3 or Perl 4 days) that looks like this (I'm simplifying greatly): my @array; push( array, $some_scalar ); Notice that the array in the push() doesn't have an @. I would assume that the code behind push knows that the first argument is supposed to be array so grabs the array from the array typeglob. Is that more or less it? If Perl is able to do that without problem, why would you need to include the @ at all?

    Read the article

  • How to pass a class method as an argument for another function in C++ and openGL?

    - by tsubasa
    I know this thing works: void myDisplay() { ... } int main() { ... glutDisplayFunc(myDisplay) ... } so I tried to include myDisplay() function to a class that I made. Because I want to overload it in the future with a different class. However, the compiler complains that argument of type 'void (ClassBlah::)()' does not match 'void(*)()' . Here is the what I try to make: class ClassBlah { .... void myDisplay() .... } ...... int main() { ... ClassBlah blah glutDisplayFunc(blah.myDisplay) ... } Does anybody knows how to fix this problem? Many thanks.

    Read the article

  • Can we have an anonymous struct as template argument?

    - by nonoitall
    The title is pretty self-explanatory, but here's a simplified example: #include <cstdio> template <typename T> struct MyTemplate { T member; void printMemberSize() { printf("%i\n", sizeof(T)); } }; int main() { MyTemplate<struct { int a; int b; }> t; // <-- compiler doesn't like this t.printMemberSize(); return 0; } The compiler complains when I try to use an anonymous struct as a template argument. What's the best way to achieve something like this without having to have a separate, named struct definition?

    Read the article

  • What is wrong with this simple type definition? (Expecting one more argument to...)

    - by fluteflute
    basic.hs: areaCircle :: Floating -> Floating areaCircle r = pi * r * r Command: *Main> :l basic.hs [1 of 1] Compiling Main ( Sheet1.hs, interpreted ) Sheet1.hs:2:15: Expecting one more argument to `Floating' In the type signature for `areaCircle': areaCircle :: Floating -> Floating Failed, modules loaded: none. I see that areaCircle :: Floating a => a -> a loads as expected. Why is the above version not acceptable?

    Read the article

  • How to write function where argument is type but not typed value?

    - by ssp
    I want to convert a string representations of few dozen enum types to enum values. It's easy to convert string to concrete type: Enum.Parse(typeof<FontStyle>,"Bold") |> unbox<FontStyle> but for now i want to write function where type and string are parameters. The best one i can write is: > let s2e (_: 'a) s = Enum.Parse(typeof<'a>,s) |> unbox<'a>;; val s2e : 'a -> string -> 'a > s2e FontStyle.Regular "Bold";; val it : FontStyle = Bold Is there any option to write something like this but with type itself as first argument?

    Read the article

  • What is the purpose of this string argument in a JavaScript function?

    - by Adel
    In the following function, there is the line: var username=getCookie("username"); Here's the whole function: function checkCookie() { var username=getCookie("username"); if (username!=null && username!="") { alert("Welcome again " + username); } else { username=prompt("Please enter your name:",""); if (username!=null && username!="") { setCookie("username",username,365); } } What is the point of the "username" argument being passed above? function getCookie(c_name) { var i,x,y,ARRcookies=document.cookie.split(";"); for (i=0;i<ARRcookies.length;i++) { x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("=")); y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1); x=x.replace(/^\s+|\s+$/g,""); if (x==c_name) { return unescape(y); } } } The whole code is here Thanks!

    Read the article

  • Is there any common fix for jQuery Firefox error: Could not convert JavaScript argument arg 0?

    - by Abuthakir
    I updated jQuery latest version v1.4.2 and getting 'Could not convert JavaScript argument arg 0' this error. Is the any common fix for this. I found some solution and they are saying that when finding dimension for display none element it will give this error. Also the following fix is working for me Placing this if (!elem || elem == document) elem = document.body above this line var computedStyle = defaultView.getComputedStyle(elem, null); I am not sure this is the proper solution. I first found this bug when using jquery blockUI plugin and after updating that plugin to latest version fixed this issue. Anyone suggest me better solution for this?

    Read the article

  • Error about TypeError (wrong argument type Module (expected Class)): app/controllers/player_profiles_controller.rb:1:in `<top (required)>'

    - by edi susanto
    hy guys . . im new at this . . sorry for the word that's not understandable and the easy question . . i'd like to ask about an error that shown below : TypeError (wrong argument type Module (expected Class)): app/controllers/player_profiles_controller.rb:1:in `' i want to test the result by render json in soapUI. does anyone know what's the problem so that the error will show up like above ? thanks before.regards,edy

    Read the article

< Previous Page | 52 53 54 55 56 57 58 59 60 61 62 63  | Next Page >