Search Results

Search found 2715 results on 109 pages for 'lazy initialization'.

Page 23/109 | < Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >

  • C++ Initialize array in constructor EXC_BAD_ACCESS

    - by user890395
    I'm creating a simple constructor and initializing an array: // Construtor Cinema::Cinema(){ // Initalize reservations for(int i = 0; i < 18; i++){ for(int j = 0; j < 12; j++){ setReservation(i, j, 0); } } // Set default name setMovieName("N/A"); // Set default price setPrice(8); } The setReservation function: void Cinema::setReservation(int row, int column, int reservation){ this->reservations[row][column] = reservation; } The setMovieName function: void Cinema::setMovieName(std::string movieName){ this->movieName = movieName; } For some odd reason when I run the program, the setMovieName function gives the following error: "Program Received Signal: EXC_BAD_ACCESS" If I take out the for-loop that initializes the array of reservations, the problem goes away and the movie name is set without any problems. Any idea what I'm doing wrong? This is the Cinema.h file: #ifndef Cinema_h #define Cinema_h class Cinema{ private: int reservations[17][11]; std::string movieName; float price; public: // Construtor Cinema(); // getters/setters int getReservation(int row, int column); int getNumReservations(); std::string getMovieName(); float getPrice(); void setReservation(int row, int column, int reservation); void setMovieName(std::string movieName); void setPrice(float price); }; #endif

    Read the article

  • Python list should be empty on class instance initialisation, but it's not. Why?

    - by canavanin
    Hi everyone! I would like to create instances of a class containing a list that's empty by default; instead of later setting this list to the final full list I would like to successively add items to it. Here's a piece of sample code illustrating this: #!/usr/bin/python class test: def __init__(self, lst=[], intg=0): self.lista = lst self.integer = intg name_dict = {} counter = 0 for name in ('Anne', 'Leo', 'Suzy'): counter += 1 name_dict[name] = test() name_dict[name].integer += 1 name_dict[name].lista.append(counter) print name, name_dict[name].integer, name_dict[name].lista When I ran the above program I expected to get Anne 1 [1] Leo 1 [2] Suzy 1 [3] as I assumed lista to always be initialised to an empty list. What I got instead was this: Anne 1 [1] Leo 1 [1, 2] Suzy 1 [1, 2, 3] If I replace self.lista = lst by self.lista = [] it works fine, just like when I add the line name_dict[name].lista = [] to the for loop. Why is it that the contents of the previous objects' lists are retained, yet their values of integer aren't? I am rather new to Python, so it would be great if someone could point out to me where my thoughts/assumptions have gone astray. Thanks a lot in advance for your replies.

    Read the article

  • What does "the application failed to initialize properly" mean?

    - by Mason Wheeler
    I just got a bug report from someone running an app I wrote under Windows XP. He says it won't start up. The application failed to initialize properly (0xc0150002). Click on OK to terminate the application. It works fine at my end, (under Windows 7,) and I don't have any Win7- or Vista-specific stuff in the program, so it should work on XP too. How do I go about tracking this down and debugging it?

    Read the article

  • What is the difference between declaring data attributes inside or outside __init__

    - by user1898540
    I'm trying to get my head around OOP in Python and I'm a bit confused when it comes to declare variables within a class. Should I declare them inside of the __init__ procedure or outside it? What's the difference? The following code works just fine: # Declaring variables within __init__ class MyClass: def __init__(self): country = "" city = "" def information(self): print "Hi! I'm from %s, (%s)"%(self.city,self.country) me = MyClass() me.country = "Spain" me.city = "Barcelona" me.information() But declaring the variables outside of the __init procedure also works: # Declaring variables outside of __init__ class MyClass: country = "" city = "" def information(self): print "Hi! I'm from %s, (%s)"%(self.city,self.country) me = MyClass() me.country = "Spain" me.city = "Barcelona" me.information()

    Read the article

  • Why does the Java compiler complain about a local variable not having been initialized here?

    - by pele
    int a = 1, b; if(a > 0) b = 1; if(a <= 0) b = 2; System.out.println(b); If I run this, I receive: Exception in thread "main" java.lang.Error: Unresolved compilation problem: The local variable b may not have been initialized at Broom.main(Broom.java:9) I know that the local variables are not initialized and is your duty to do this, but in this case, the first if doesn't initialize the variable?

    Read the article

  • initWithCoder breaking my touch events (touchBegan, touchMoved, etc)

    - by Adam
    So I have a UIView that has been setup, and in each touch event handler I have an NSLog fire off a message to the console. - (void) touchesBegan:(NSSSet*)touches withEvent:(UIEvent*)event { NSLog(@"touchesBegan"); } And that pretty much works as expected. But once I implement initWithCoder (even blank) - (id)initWithCoder:(NSCoder*)coder { return self; } I no longer receive the message to my console (or can hit breakpoints obviously). This is my first app so I'm probably missing something dumb, but I've looked through various example apps and I don't appear to be missing any code that would re-enable touch events.

    Read the article

  • Object Deletion: use parent or not

    - by metdos
    Which one do you prefer to delete objects? Especially in QT, but other practices are also welcome. These two alternatives seem same to me, are they? 1.Bound to another class, and destroy when it is destroyed. SomeClass::SomeClass{ socket_ = new QTcpSocket(this); } or 2.Destroy in the destructor of class SomeClass::SomeClass{ socket_ = new QTcpSocket(); } SomeClass::~SomeClass{ delete socket_; }

    Read the article

  • Is it good practice to initialize array in C/C++?

    - by sand
    I recently encountered a case where I need to compare two files (golden and expected) for verification of test results and even though the data written to both the files were same, the files does not match. On further investigation, I found that there is a structure which contains some integers and a char array of 64 bytes, and not all the bytes of char array were getting used in most of the cases and unused fields from the array contain random data and that was causing the mismatch. This brought me ask the question whether it is good practice to initialize the array in C/C++ as well, as it is done in Java?

    Read the article

  • Where to add an observer to the NotificationCenter in a UITableViewController

    - by Saifis
    I want to send a notification from a UITableViewController-A to UITableViewController-B. I was adding the observer in the initwithCoder of the UITableViewController that is supposed to catch the notifications. The classes are correlated as folows RootViewController ===NavigationController-A =====UITableViewController-A ===NavigationController-B =====UITableViewController-B I need to add the observer before the views are actually loaded because notifications may be sent before the view is called. However I have been told that initializing in the initWithCoder method in a UIViewController is not advisable, and was told to add the observer in the AppDelegate. Are there any other suggestions for doing this?

    Read the article

  • Undefined / Uninitialized default values in a class

    - by Jir
    Let's suppose you have this class: class A { public: A () {} A (double val) : m_val(val) {} ~A () {} private: double m_val; }; Once I create an instance of A, how can I check if m_val has been initialized/defined? Put it in other words, is there a way to know if m_val has been initialized/defined or not? Something along the lines of the defined operator in Python, I suppose. (But correct me if I'm wrong.) I thought of modifying the class and the c-tors the following way: class A { public: A () : defined(false) {} A (double val) : m_val(val), defined(true) {} ~A () {} private: double m_val; bool defined; }; How do you rate this solution? Any suggestion? TIA, Chris

    Read the article

  • c++ Initializing a struct with an array as a member

    - by Drew Shafer
    I've got the following reduced testcase: typedef struct TestStruct { int length; int values[]; }; TestStruct t = {3, {0, 1, 2}}; This works with Visual C++, but doesn't compile with g++ under linux. Can anyone help me make this specific kind of initializer portable? Additional details: the actual structure I'm working with has several other int values, and the array can range in length from a single entry to over 1800 entries. Any help much appreciated. Thanks!

    Read the article

  • c++/boost: use tuple ctors when subclassing

    - by bbb
    Hi there, is there some way to use a boost tuple's ctors as an addition to the subclass methods (and ctors) like here? // typedef boost::tuple<int, SomeId, SomeStatus> Conn; // Conn(1); // works and initializes using default ctors of Some* struct Conn : boost::tuple<int, AsynchId, AccDevRetStatus> {}; Conn(1); // "no matching function call" (but i want it so much) T.H.X.

    Read the article

  • jQuery global variable problem

    - by Emanuel
    var id = $(this).children().html(); // id is 5 $.ajax({ url: 'ajax.php?id=' + id, success: function(data) { id = data; // id is 1 } }); if(id == 1){ // id is again 5 ... } Why in the following example I can't reinitialize the id variable? What is wrong? Thanks.

    Read the article

  • How to default-initialize local variables of built-in types in C++?

    - by sharptooth
    How do I default-initialize a local variable of primitive type in C++? For example if a have a typedef: typedef unsigned char boolean;//that's Microsoft RPC runtime typedef I'd like to change the following line: boolean variable = 0; //initialize to some value to ensure reproduceable behavior retrieveValue( &variable ); // do actual job into something that would automagically default-initialize the variable - I don't need to assign a specific value to it, but instead I only need it to be intialized to the same value each time the program runs - the same stuff as with a constructor initializer list where I can have: struct Struct { int Value; Struct() : Value() {} }; and the Struct::Value will be default-initialized to the same value every time an instance is cinstructed, but I never write the actual value in the code. How can I get the same behavior for local variables?

    Read the article

  • Statically initialize anonymous union in C++

    - by wpfwannabe
    I am trying to statically initialize the following structure in Visual Studio 2010: struct Data { int x; union { char ch; const Data* data; }; }; The following is fails with error C2440: 'initializing' : cannot convert from 'Data *' to 'char'. static Data d1; static Data d = {1, &d1}; I have found references to some ways this can be initialized properly but none of them work in VS2010. Any ideas?

    Read the article

  • How/When/Where to Extend Gem Classes (via class_eval and Modules) in Rails 3?

    - by viatropos
    What is the recommended way to extend class behavior, via class_eval and modules (not by inheritance) if I want to extend a class buried in a Gem from a Rails 3 app? An example is this: I want to add the ability to create permalinks for tags and categories (through the ActsAsTaggableOn and ActsAsCategory gems). They have defined Tag and Category models. I want to basically do this: Category.class_eval do has_friendly_id :title end Tag.class_eval do has_friendly_id :title end Even if there are other ways of adding this functionality that might be specific to the gem, what is the recommended way to add behavior to classes in a Rails 3 application like this? I have a few other gems I've created that I want to do this to, such as a Configuration model and an Asset model. I would like to be able to add create an app/models/configuration.rb model class to my app, and it would act as if I just did class_eval. Anyways, how is this supposed to work? I can't find anything that covers this from any of the current Rails 3 blogs/docs/gists.

    Read the article

  • Best way to initialise / clear a string variable cocoa

    - by Spider-Paddy
    I have a routine that parses text via a loop. At the end of each record I need to clear my string variables but I read that someString = @"" actually just points to a new string & causes a memory leak. What is the best way to handle this? Should I rather use mutable string vars and use setString:@"" between iterations?

    Read the article

  • intialization with a nibFIle failed

    - by zp26
    Hi, I have a problem. I try to initialize a variabile in a classViewController created inside a xib file. I try with the code below but when i append a object to array, these array isn't initialized. Can you help me? thanks and sorry for my english. #import <UIKit/UIKit.h> @interface AccelerometroViewController : UIViewController <UIAccelerometerDelegate, UITextFieldDelegate, UIAlertViewDelegate>{ //..... NSMutableArray *arrayPosizioni; NSMutableArray *arrayPosizioniCorrenti; NSString *nomePosizioneCorrente; } -(IBAction)salvaPosizione; //... @property (nonatomic, assign) NSMutableArray *arrayPosizioni; @property (nonatomic, assign) NSMutableArray *arrayPosizioniCorrenti; @property (nonatomic, assign) NSString *nomePosizioneCorrente; @end #import "AccelerometroViewController.h" #import "Position.h" @implementation AccelerometroViewController float actualX; float actualY; float actualZ; @synthesize arrayPosition; @synthesize arrayCurrentPosition; @synthesize nameCurrentPosition; -(id)init { self = [super init]; if (self != nil) { arrayPosition = [[NSMutableArray alloc]init]; arrayCurrentPosition = [[NSMutableArray alloc]init]; nameCurrentPosition = [NSString stringWithFormat:@"noPosition"]; actualX = 0; actualY = 0; actualZ = 0; } return self; } -(void)updateTextView:(NSString*)nomePosizione { NSString *string = [NSString stringWithFormat:@"%@", nameCurrentPosition]; textEvent.text = [textEvent.text stringByAppendingString:@"\n"]; textEvent.text = [textEvent.text stringByAppendingString:string]; } -(IBAction)savePosition{ Posizione *newPosition; newPosition = [[Position alloc]init]; if([newPosition setValue:(NSString*)fieldNomePosizione.text:(float)actualX:(float)actualY:(float)actualZ]){ //setValue is a method of Position. I'm sure that this method is correct UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Salvataggio Posizione" message:@"Posizione salvata con successo" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; [alert show]; [alert release]; [arrayPosition addObject:newPosition]; } else{ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Salvataggio osizione" message:@"Errore nel salvataggio" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; [alert show]; [alert release]; } } - (void) initialise { arrayPosition = [[NSMutableArray alloc] init]; arrayCurrentPosition = [[NSMutableArray alloc] init]; nameCurrentPosition = @"noPosition"; actualX = 0; actualY = 0; actualZ = 0; } - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle { if (self = [super initWithNibName:nibName bundle:bundle]) { [self initialise]; } }

    Read the article

  • C# Automatic Properties - Still null after +=?

    - by Sam Schutte
    This seems like a bug to me... I accept that automatic properties, defined as such: public decimal? Total { get; set; } Will be null when they are first accessed. They haven't been initialized, so of course they are null. But, even after setting their value through +=, this decimal? still remains null. So after: Total += 8; Total is still null. How can this be correct? I understand that it's doing a (null + 8), but seems strange that it doesn't pick up that it means it should just be set to 8... Addendums: I made the "null + 8" point in my question - but notice that it works with strings. So, it does null + "hello" just fine, and returns "hello". Therefore, behind the scenes, it is initializing the string to a string object with the value of "hello". The behavior should be the same for the other types, IMO. It might be because a string can accept a null as a value, but still, a null string is not an initialized object, correct? Perhaps it's just because a string isn't a nullable...

    Read the article

  • How can i initialise a server on startup?

    - by djerry
    Hey all, I need to make some connections on startup of a server. I'm using the wcf technology for this client-server application. The problem is that the constructor of the server isn't called at any time, so for the moment, i initialize the connections when the first client makes a connection. But this generates problems in a further part. This is my server setup: private static ServiceHost _svc; static void Main(string[] args) { NetTcpBinding binding = new NetTcpBinding(SecurityMode.Message); Uri address = new Uri("net.tcp://localhost:8000"); _svc = new ServiceHost(typeof(MonitoringSystemService), address); publishMetaData(_svc, "http://localhost:8001"); _svc.AddServiceEndpoint(typeof(IMonitoringSystemService), binding, "Monitoring Server"); _svc.Open(); Console.WriteLine("Listener service gestart op net.tcp://localhost:8000/Monitoring"); Console.ReadLine(); } private static void publishMetaData(ServiceHost svc, string sEndpointAddress) { ServiceMetadataBehavior smb = svc.Description.Behaviors.Find<ServiceMetadataBehavior>(); if (smb != null) { smb.HttpGetEnabled = true; smb.HttpGetUrl = new Uri(sEndpointAddress); } else { smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; smb.HttpGetUrl = new Uri(sEndpointAddress); svc.Description.Behaviors.Add(smb); } } How can i start the server without waiting for a client to logon so i can initialize it. Thanks in advance.

    Read the article

  • C++ constructor problem, values not being set

    - by 2Real
    Hi, I'm new to C++ and I'm trying to figure out this problem I'm having with my constructor for one of my classes. What happens is... all my variables are initialized properly except two (health and type). #pragma once #include <irrlicht.h> #include <vector> #include <cassert> using namespace irr; using namespace core; using namespace scene; enum { PLAYER = 0, NPC = 1, SOLDIER = 2, CHAINGUNNER = 3 }; class Model { public: Model(void); Model(int id, std::vector<ISceneNode*> modelVec, int modType); ~Model(void); std::vector<int> path; std::vector<ISceneNode*> model; int endNode; int type; int animate; int health; u32 lastAnimation; private: int mId; }; #include "Model.h" Model::Model(void) { //assert(false); } Model::Model(int id, std::vector<ISceneNode*> modelVec, int modType) { path = std::vector<int>(); model = modelVec; endNode = 0; type = modType; animate = 0; health = 100; lastAnimation = 0; mId = id; } Model::~Model(void) {} I create a model with Model soldier(id, model, SOLDIER) Everything is set properly except type and health. I've tried many different things, but I cannot figure out my problem. I'm not sure but the default constructor is being called. It doesn't make sense because I make no called to that constructor. Thanks,

    Read the article

< Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >