Search Results

Search found 654 results on 27 pages for 'zz coder'.

Page 2/27 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • initWithCoder works, but init seems to be overwriting my objects properties?

    - by Zigrivers
    Hi guys, I've been trying to teach myself how to use the Archiving/Unarchiving methods of NSCoder, but I'm stumped. I have a Singleton class that I have defined with 8 NSInteger properties. I am trying to save this object to disk and then load from disk as needed. I've got the save part down and I have the load part down as well (according to NSLogs), but after my "initWithCoder:" method loads the object's properties appropriately, the "init" method runs and resets my object's properties back to zero. I'm probably missing something basic here, but would appreciate any help! My class methods for the Singleton class: + (Actor *)shareActorState { static Actor *actorState; @synchronized(self) { if (!actorState) { actorState = [[Actor alloc] init]; } } return actorState; } -(id)init { if (self = [super init]) { NSLog(@"New Init for Actor started...\nStrength: %d", self.strength); } return self; } -(id)initWithCoder:(NSCoder *)coder { if (self = [super init]) { strength = [coder decodeIntegerForKey:@"strength"]; dexterity = [coder decodeIntegerForKey:@"dexterity"]; stamina = [coder decodeIntegerForKey:@"stamina"]; will = [coder decodeIntegerForKey:@"will"]; intelligence = [coder decodeIntegerForKey:@"intelligence"]; agility = [coder decodeIntegerForKey:@"agility"]; aura = [coder decodeIntegerForKey:@"aura"]; eyesight = [coder decodeIntegerForKey:@"eyesight"]; NSLog(@"InitWithCoder executed....\nStrength: %d\nDexterity: %d", self.strength, self.dexterity); [self retain]; } return self; } -(void) encodeWithCoder:(NSCoder *)encoder { [encoder encodeInteger:strength forKey:@"strength"]; [encoder encodeInteger:dexterity forKey:@"dexterity"]; [encoder encodeInteger:stamina forKey:@"stamina"]; [encoder encodeInteger:will forKey:@"will"]; [encoder encodeInteger:intelligence forKey:@"intelligence"]; [encoder encodeInteger:agility forKey:@"agility"]; [encoder encodeInteger:aura forKey:@"aura"]; [encoder encodeInteger:eyesight forKey:@"eyesight"]; NSLog(@"encodeWithCoder executed...."); } -(void)dealloc { //My dealloc stuff goes here [super dealloc]; } I'm a noob when it comes to this stuff and have been trying to teach myself for the last month, so forgive anything obvious. Thanks for the help!

    Read the article

  • Would be good to include your freelancer account in your Resume / CV when applying for a job?

    - by Oscar Mederos
    I've been working as a freelancer for about two years in vWorker. Any person can visit a coder's profile, and see in how many projects the coder has worked on, (if the coders allows) see how much the coder obtained in each project, ratings, feedbacks, etc. Would be good to include a freelancer account in your Resume / CV when applying for a job? Is it something you would do if you have finished several projects there?

    Read the article

  • Can't install or update Ubuntu after using parameter acpi_osi = Linux

    - by Lucas Leitão
    I recently had an issue with my acer 4736z notebook because I was having a blank screen after booting the OS, then someone told me to use the parameter GRUB_CMDLINE_LINUX_DEFAULT = "quiet splash acpi_osi = Linux" after quiet splash inside the grub. It worked for me, but since then I can't install a thing or update anything on Linux because it says Removing linux-image-extra-3.5.0-17-generic ... Examining /etc/kernel/postrm.d . run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.5.0-17-generic /boot/vmlinuz-3.5.0-17-generic update-initramfs: Deleting /boot/initrd.img-3.5.0-17-generic run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.5.0-17-generic /boot/vmlinuz-3.5.0-17-generic /usr/sbin/grub-mkconfig: 11: /etc/default/grub: GRUB_CMDLINE_LINUX_DEFAULT: not found run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 127 Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-extra-3.5.0-17-generic.postrm line 328. dpkg: erro ao processar linux-image-extra-3.5.0-17-generic (--remove): sub-processo script post-removal instalado retornou estado de saída de erro 1 Removendo linux-image-3.5.0-17-generic ... Examining /etc/kernel/postrm.d . run-parts: executing /etc/kernel/postrm.d/initramfs-tools 3.5.0-17-generic /boot/vmlinuz-3.5.0-17-generic update-initramfs: Deleting /boot/initrd.img-3.5.0-17-generic run-parts: executing /etc/kernel/postrm.d/zz-update-grub 3.5.0-17-generic /boot/vmlinuz-3.5.0-17-generic /usr/sbin/grub-mkconfig: 11: /etc/default/grub: GRUB_CMDLINE_LINUX_DEFAULT: not found run-parts: /etc/kernel/postrm.d/zz-update-grub exited with return code 127 Failed to process /etc/kernel/postrm.d at /var/lib/dpkg/info/linux-image-3.5.0-17-generic.postrm line 328. dpkg: erro ao processar linux-image-3.5.0-17-generic (--remove): sub-processo script post-removal instalado retornou estado de saída de erro 1 Erros foram encontrados durante o processamento de: linux-image-extra-3.5.0-17-generic linux-image-3.5.0-17-generic E: Sub-process /usr/bin/dpkg returned an error code (1) I already tried to remove older kernels but it gives me the same message. Do you have a clue about what should I do?

    Read the article

  • NSKeyedUnarchiver chokes when trying to unarchive more than one object

    - by ajduff574
    We've got a custom matrix class, and we're attempting to archive and unarchive an NSArray containing four of them. The first seems to get unarchived fine (we can see that initWithCoder is called once), but then the program simply hangs, using 100% CPU. It doesn't continue or output any errors. These are the relevant methods from the matrix class (rows, columns, and matrix are our only instance variables): -(void)encodeWithCoder:(NSCoder*) coder { float temp[rows * columns]; for(int i = 0; i < rows; i++) { for(int j = 0; j < columns; j++) { temp[columns * i + j] = matrix[i][j]; } } [coder encodeBytes:(const void *)temp length:rows*columns*sizeof(float) forKey:@"matrix"]; [coder encodeInteger:rows forKey:@"rows"]; [coder encodeInteger:columns forKey:@"columns"]; } -(id)initWithCoder:(NSCoder *) coder { if (self = [super init]) { rows = [coder decodeIntegerForKey:@"rows"]; columns = [coder decodeIntegerForKey:@"columns"]; NSUInteger * len; *len = (unsigned int)(rows * columns * sizeof(float)); float * temp = (float * )[coder decodeBytesForKey:@"matrix" returnedLength:len]; matrix = (float ** )calloc(rows, sizeof(float*)); for (int i = 0; i < rows; i++) { matrix[i] = (float*)calloc(columns, sizeof(float)); } for(int i = 0; i < rows *columns; i++) { matrix[i / columns][i % columns] = temp[i]; } } return self; } And this is really all we're trying to do: NSArray * weightMatrices = [NSArray arrayWithObjects:w1,w2,w3,w4,nil]; [NSKeyedArchiver archiveRootObject:weightMatrices toFile:@"weights.archive"]; NSArray * newWeights = [NSKeyedUnarchiver unarchiveObjectWithFile:@"weights.archive"]; What's driving us crazy is that we can archive and unarchive a single matrix just fine. We've done so (successfully) with a matrix many times larger than these four combined.

    Read the article

  • Lua and Objective C not running script.

    - by beta
    I am trying to create an objective c interface that encapsulates the functionality of storing and running a lua script (compiled or not.) My code for the script interface is as follows: #import <Cocoa/Cocoa.h> #import "Types.h" #import "lua.h" #include "lualib.h" #include "lauxlib.h" @interface Script : NSObject<NSCoding> { @public s32 size; s8* data; BOOL done; } @property s32 size; @property s8* data; @property BOOL done; - (id) initWithScript: (u8*)data andSize:(s32)size; - (id) initFromFile: (const char*)file; - (void) runWithState: (lua_State*)state; - (void) encodeWithCoder: (NSCoder*)coder; - (id) initWithCoder: (NSCoder*)coder; @end #import "Script.h" @implementation Script @synthesize size; @synthesize data; @synthesize done; - (id) initWithScript: (s8*)d andSize:(s32)s { self = [super init]; self->size = s; self->data = d; return self; } - (id) initFromFile:(const char *)file { FILE* p; p = fopen(file, "rb"); if(p == NULL) return [super init]; fseek(p, 0, SEEK_END); s32 fs = ftell(p); rewind(p); u8* buffer = (u8*)malloc(fs); fread(buffer, 1, fs, p); fclose(p); return [self initWithScript:buffer andSize:size]; } - (void) runWithState: (lua_State*)state { if(luaL_loadbuffer(state, [self data], [self size], "Script") != 0) { NSLog(@"Error loading lua chunk."); return; } lua_pcall(state, 0, LUA_MULTRET, 0); } - (void) encodeWithCoder: (NSCoder*)coder { [coder encodeInt: size forKey: @"Script.size"]; [coder encodeBytes:data length:size forKey:@"Script.data"]; } - (id) initWithCoder: (NSCoder*)coder { self = [super init]; NSUInteger actualSize; size = [coder decodeIntForKey: @"Script.size"]; data = [[coder decodeBytesForKey:@"Script.data" returnedLength:&actualSize] retain]; return self; } @end Here is the main method: #import "Script.h" int main(int argc, char* argv[]) { Script* script = [[Script alloc] initFromFile:"./test.lua"]; lua_State* state = luaL_newstate(); luaL_openlibs(state); luaL_dostring(state, "print(_VERSION)"); [script runWithState:state]; luaL_dostring(state, "print(_VERSION)"); lua_close(state); } And the lua script is just: print("O Hai World!") Loading the file is correct, but I think it messes up at pcall. Any Help is greatly appreciated. Heading

    Read the article

  • Xcode / Interface Builder - better workflow from designer to coder?

    - by tbarbe
    Were dealing with some pretty custom UI elements while building our OSX / Cocoa and iPhone / IPad apps. I was wondering if anyone has good recommendations or tricks for getting a better workflow between UI designers and coders while using Xcode / Interface Builder? It seems that many things require programmatic settings with UI editing in Cocoa... if you stray from the pre-built UI elements then you can't really easily drag-drop build a UI... instead we end up handing off a design doc ( photoshop/illustrator ) and then the poor developer has to deal with recreating this masterpiece in code or by using interface builder - usually a combination of both. This work flow is leading us to not so great results and we have to re-iterate around the UI elements to get them to work better. We love CSS and / or Flash designer to developer workflow where the UI could look exactly as it should and the hand off to developer was more seamless. Is there anyone out there who has some tricks - or insights into getting better workflow when using tools like Xcode / Interface Builder and doing Cocoa apps?

    Read the article

  • Business person turned into coder? How and why? Inspire the non-technical.

    - by huisjames
    I graduated with a Business degree. Two years later, I finally realized the power of programming - the power to "invent." I wish I realized this in high school. Nevertheless, I tried to self-teach C# but found it difficult. Then I pivoted to learn PHP two months ago and I have been able to build things I thought was beyond my abilities. Has anyone had the same experience? Or self-taught programming? What lessons did you learn?

    Read the article

  • How to serialize object containing NSData?

    - by AO
    I'm trying to serialize an object containing a number of data fields...where one of the fields is of datatype NSData which won't serialize. I've followed instructions at http://www.isolated.se but my code (see below) results in the error "[NSConcreteData data]: unrecognized selector sent to instance...". How do I serialize my object? Header file: @interface Donkey : NSObject<NSCoding> { NSString* s; NSData* d; } @property (nonatomic, retain) NSString* s; @property (nonatomic, retain) NSData* d; - (NSData*) serialize; @end Implementation file: @implementation Donkey @synthesize s, d; static NSString* const KEY_S = @"string"; static NSString* const KEY_D = @"data"; - (void) encodeWithCoder:(NSCoder*)coder { [coder encodeObject:self.s forKey:KEY_S]; [coder encodeObject:self.d forKey:KEY_D]; } - (id) initWithCoder:(NSCoder*)coder; { if(self = [super init]) { self.s = [coder decodeObjectForKey:KEY_STRING]; self.d [coder decodeObjectForKey:KEY_DATA]; } return self; } - (NSData*) serialize { return [NSKeyedArchiver archivedDataWithRootObject:self]; } @end

    Read the article

  • Storing arrays in NSUserDefaultsController

    - by neoneye
    Currently I use NSUserDefaults and I'm interested in using NSUserDefaultsController, so that I get notifications when things change. Below is my current code. items = /* NSArray of MYItem's */; NSData* data = [NSKeyedArchiver archivedDataWithRootObject:items]; [[NSUserDefaults standardUserDefaults] setObject:data forKey:kMYItems]; How should I rework my code to store items in NSUserDefaultsController ? Is NSKeyedArchiver the smartest way to store arrays? @interface MYItem : NSObject <NSCoding> { NSString* name; NSString* path; } @property (copy) NSString* name; @property (copy) NSString* path; @end @implementation MYItem @synthesize name, path; -(void)encodeWithCoder:(NSCoder*)coder { [coder encodeObject:name forKey:@"name"]; [coder encodeObject:path forKey:@"path"]; } -(id)initWithCoder:(NSCoder*)coder { [super init]; [self setName:[coder decodeObjectForKey:@"name"]]; [self setPath:[coder decodeObjectForKey:@"path"]]; return self; } @end

    Read the article

  • game state singleton cocos2d, initWithEncoder always returns null

    - by taber
    Hi, I'm trying to write a basic test "game state" singleton in cocos2d, but for some reason upon loading the app, initWithCoder is never called. Any help would be much appreciated, thanks. Here's my singleton GameState.h: #import "cocos2d.h" @interface GameState : NSObject <NSCoding> { NSInteger level, score; Boolean seenInstructions; } @property (readwrite) NSInteger level; @property (readwrite) NSInteger score; @property (readwrite) Boolean seenInstructions; +(GameState *) sharedState; +(void) loadState; +(void) saveState; @end ... and GameState.m: #import "GameState.h" #import "Constants.h" @implementation GameState static GameState *sharedState = nil; @synthesize level, score, seenInstructions; -(void)dealloc { [super dealloc]; } -(id)init { if(!(self = [super init])) return nil; level = 1; score = 0; seenInstructions = NO; return self; } +(void)loadState { @synchronized([GameState class]) { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *saveFile = [documentsDirectory stringByAppendingPathComponent:kSaveFileName]; Boolean saveFileExists = [[NSFileManager defaultManager] fileExistsAtPath:saveFile]; if(!sharedState) { sharedState = [GameState sharedState]; } if(saveFileExists == YES) { [sharedState release]; sharedState = [[NSKeyedUnarchiver unarchiveObjectWithFile:saveFile] retain]; } // at this point, sharedState is null, saveFileExists is 1 if(sharedState == nil) { // this always occurs CCLOG(@"Couldn't load game state, so initialized with defaults"); sharedState = [self sharedState]; } } } +(void)saveState { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *saveFile = [documentsDirectory stringByAppendingPathComponent:kSaveFileName]; [NSKeyedArchiver archiveRootObject:[GameState sharedState] toFile:saveFile]; } +(GameState *)sharedState { @synchronized([GameState class]) { if(!sharedState) { [[GameState alloc] init]; } return sharedState; } return nil; } +(id)alloc { @synchronized([GameState class]) { NSAssert(sharedState == nil, @"Attempted to allocate a second instance of a singleton."); sharedState = [super alloc]; return sharedState; } return nil; } +(id)allocWithZone:(NSZone *)zone { @synchronized([GameState class]) { if(!sharedState) { sharedState = [super allocWithZone:zone]; return sharedState; } } return nil; } ... -(void)encodeWithCoder:(NSCoder *)coder { [coder encodeInt:level forKey:@"level"]; [coder encodeInt:score forKey:@"score"]; [coder encodeBool:seenInstructions forKey:@"seenInstructions"]; } -(id)initWithCoder:(NSCoder *)coder { CCLOG(@"initWithCoder called"); self = [super init]; if(self != nil) { CCLOG(@"initWithCoder self exists"); level = [coder decodeIntForKey:@"level"]; score = [coder decodeIntForKey:@"score"]; seenInstructions = [coder decodeBoolForKey:@"seenInstructions"]; } return self; } @end ... I'm saving the state on app exit, like this: - (void)applicationWillTerminate:(UIApplication *)application { [GameState saveState]; [[CCDirector sharedDirector] end]; } ... and loading the state when the app finishes loading, like this: - (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [GameState loadState]; ... } I've tried moving around where I call loadState too, for example in my main CCScene, but that didn't seem to work either. Thanks again in advance.

    Read the article

  • Windows-to-linux: Putty with SSH and private/public key pair

    - by Johnny Kauffman
    I spent about 3 hours trying to figure out how to connect to a linux box from my windows machine using putty without having to send the password. This is connecting to an Ubuntu server that is using OpenSSH. The private key is SSH-2 RSA, 1024 bits. I am connecting using SSH2. I have run into the more common problems already: Putty generated the public key in the "wrong format". I have corrected this (as seen on this blog post). However, since I am not yet connected, I cannot absolutely confirm that this file is in the correct format. The key is all on a single line now, and I have tried adding/removing line breaks at the end of the file. I've also tried the public file doctoring process a few times to ensure that I haven't flubbed up the manual conversion. Even so, I have no way to verify accuracy here. The permissions were at once point wrong as well, specifically meaning that the file had too many permissions. I had to solve this too and I know it got past this because I no longer see a related error in /var/log/auth.log. I've tried both authorized_keys and authorized_keys2 in case the server has an old version of OpenSSH, but this changed nothing. I do have access as a user. After this keyfile stuff fails, I can enter my password instead The only remaining nibble of information I have is that it claims I have the alleged password wrong: sshd[22288]: Failed password for zzzzzzz from zz.zz.zz.zz port 53620 ssh2 Even so, as far as I can tell, this is just a lazy try/catch somewhere, since I don't think there's a password involved at all. I see nothing else in any of the /var/log files of use. What else could be wrong?

    Read the article

  • To display the field values submitted with AJAX [closed]

    - by work
    Here is the code:I want to post the field values entered in this code to the page ajaxpost.php using Ajax and then do some operations there. What would be code required to be written in ajaxpost.php <html> <head> <script type="text/javascript"> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } var zz=document.f1.dd.value; //alert(zz); var qq= document.f1.cc.value; xmlhttp.open("POST","ajaxpost.php",true); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("dd=zz&cc=qq"); } </script> </head> <body> <h2>AJAX</h2> <form name="f1"> <input type="text" name="dd"> <input type="text" name="cc"> <button type="button" onclick="loadXMLDoc()">Request data</button> <div id="myDiv"></div> </form> </body> </html>

    Read the article

  • What's the best way to manage a multi-user project on github?

    - by Jim
    I'm looking to host a new project on github. This project will be worked on by two coders. One of these coders will also be the project manager who will have overall control over the github repo. I've followed the instructions regarding forking a github project at http://help.github.com/forking/. This all works fine and I'm working on the basis that the main repo is controlled by the lead coder, with the secondary coder working on a fork and submitting pull requests to the lead. A problem arises with this, however, when changes are made to the main branch and not pulled by the secondary coder into their fork. The secondary coder could then make changes to their own fork and submit a pull request to the lead, only for their patches to not match up with the main branch. What's the best way to manage this? I've not committed too much time to git/github, so I'm totally up for checking out other hosted solutions if they're better. Simplicity is the key!

    Read the article

  • pfSense 2.1 OpenVPN client not using tunnelled interface

    - by Brian M. Hunt
    I'm having some trouble getting OpenVPN working on my pfSense box. The issue is quite strange to me. When I have the OpenVPN turned on, only my router is able to connect to the Internet. From the router I can use ping, links, etc., and connections work exactly as expected - through the VPN, with the IP address assigned by my VPN provider (Proxy.sh, incidentally). However, none of the clients on the local network can connect to the Internet. I get timeouts when using ping or a web browser. I can ping my router, and the IP address of the gateway. When I switch the default gateway from the VPN to my ISP's gateway, all works exactly as expected. Here the routing table (netstat -r) when in VPN mode, and a key for it: IPv4 Destination Gateway Flags Refs Use Mtu Netif Expire 0.0.0.0/1 10.XX.X.53 UGS 0 122 1500 ovpnc1 = default 10.XX.X.53 UGS 0 235 1500 ovpnc1 8.8.8.8 10.XX.X.53 UGHS 0 82 1500 ovpnc1 10.XX.X.1/32 10.11.0.53 UGS 0 0 1500 ovpnc1 10.XX.X.53 link#12 UH 0 0 1500 ovpnc1 10.XX.X.54 link#12 UHS 0 0 16384 lo0 ZZ.XX.XXX.0/20 link#1 U 0 83 1500 re0 ZZ.XX.XXX.XXX link#1 UHS 0 0 16384 lo0 127.0.0.1 link#9 UH 0 12 16384 lo0 128.0.0.0/1 10.11.0.53 UGS 0 123 1500 ovpnc1 192.168.1.0/24 link#11 U 0 1434 1500 ue0 192.168.1.1 link#11 UHS 0 0 16384 lo0 YYY.YYY.YYY.YYY/32 ZZ.XX.XXX.1 UGS 0 249 1500 re0 IP addresses 10.XX.X.53/54 - My DHCP-assigned IP address/pair from the VPN provider ZZ.XX.XXX.XXX - My external IP assigned by my ISP YYY.YYY.YYY.YYY - The external IP assigned by the VPN provider Interfaces ovpnc1 - My VPN client interface re0 - My LAN interface ue0 - My WAN interface This looks essentially what I would expect it to be. The default route is through the VPN provider. The VPN address is routed through the ISP-assigned IP address. I am not sure what would be wrong here. So figuring this was a firewall issue, I basically tried enabling all in/out traffic. This did not seem to remedy the problem. Also figuring it could possibly be some client networking issue, I restarted the clients on the LAN. This did not help. I also ran route flush and reset the routes manually. So I am a bit stumped, and would be very grateful for any thoughts on what the problem might be.

    Read the article

  • iPhone SDK NSString To NSDate

    - by disp
    I got a string from parsing a XML file which looks like this: Fri, 09 Apr 2010 00:00:45 +0200 and the corresponding pattern should be this "EEE, dd MMM yyyy HH:mm:ss ZZ", but I get (null). This is my code: NSString *dateString = @"Fri, 09 Apr 2010 00:00:45 +0200"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZ"]; NSDate *date = [dateFormatter dateFromString:dateString]; NSLog(@"date:%@",date); // result date:(null) Edit: This works for me now, I had to switch to en-US locale: NSLocale* usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setLocale:usLocale]; [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZ"]; NSDate *date = [dateFormatter dateFromString:dateString];

    Read the article

  • C++ destructor seems to be called 'early'

    - by suicideducky
    Please see the "edit" section for the updated information. Sorry for yet another C++ dtor question... However I can't seem to find one exactly like mine as all the others are assigning to STL containers (that will delete objects itself) whereas mine is to an array of pointers. So I have the following code fragment #include<iostream> class Block{ public: int x, y, z; int type; Block(){ x=1; y=2; z=3; type=-1; } }; template <class T> class Octree{ T* children[8]; public: ~Octree(){ for( int i=0; i<8; i++){ std::cout << "del:" << i << std::endl; delete children[i]; } } Octree(){ for( int i=0; i<8; i++ ) children[i] = new T; } // place newchild in array at [i] void set_child(int i, T* newchild){ children[i] = newchild; } // return child at [i] T* get_child(int i){ return children[i]; } // place newchild at [i] and return the old [i] T* swap_child(int i, T* newchild){ T* p = children[i]; children[i] = newchild; return p; } }; int main(){ Octree< Octree<Block> > here; std::cout << "nothing seems to have broken" << std::endl; } Looking through the output I notice that the destructor is being called many times before I think it should (as Octree is still in scope), the end of the output also shows: del:0 del:0 del:1 del:2 del:3 Process returned -1073741819 (0xC0000005) execution time : 1.685 s Press any key to continue. For some reason the destructor is going through the same point in the loop twice (0) and then dying. All of this occures before the "nothing seems to have gone wrong" line which I expected before any dtor was called. Thanks in advance :) EDIT The code I posted has some things removed that I thought were unnecessary but after copying and compiling the code I pasted I no longer get the error. What I removed was other integer attributes of the code. Here is the origional: #include<iostream> class Block{ public: int x, y, z; int type; Block(){ x=1; y=2; z=3; type=-1; } Block(int xx, int yy, int zz, int ty){ x=xx; y=yy; z=zz; type=ty; } Block(int xx, int yy, int zz){ x=xx; y=yy; z=zz; type=0; } }; template <class T> class Octree{ int x, y, z; int size; T* children[8]; public: ~Octree(){ for( int i=0; i<8; i++){ std::cout << "del:" << i << std::endl; delete children[i]; } } Octree(int xx, int yy, int zz, int size){ x=xx; y=yy; z=zz; size=size; for( int i=0; i<8; i++ ) children[i] = new T; } Octree(){ Octree(0, 0, 0, 10); } // place newchild in array at [i] void set_child(int i, T* newchild){ children[i] = newchild; } // return child at [i] T* get_child(int i){ return children[i]; } // place newchild at [i] and return the old [i] T* swap_child(int i, T* newchild){ T* p = children[i]; children[i] = newchild; return p; } }; int main(){ Octree< Octree<Block> > here; std::cout << "nothing seems to have broken" << std::endl; } Also, as for the problems with set_child, get_child and swap_child leading to possible memory leaks this will be solved as a wrapper class will either use get before set or use swap to get the old child and write this out to disk before freeing the memory itself. I am glad that it is not my memory management failing but rather another error. I have not made a copy and/or assignment operator yet as I was just testing the block tree out, I will almost certainly make them all private very soon. This version spits out -1073741819. Thank you all for your suggestions and I apologise for highjacking my own thread :$

    Read the article

  • Subquery works in 9i but not in 11g

    - by Zsuetam
    Statement below is working on Oracle 9i but not on Oracle 11g SELECT * FROM ( SELECT 0 scrnfail_rate, '9' zz, 7 hh FROM DUAL UNION ALL SELECT 0 scrnfail_rate, '9' zz, 7 hh FROM DUAL ) WHERE zz IS NOT NULL AND TO_CHAR (hh) NOT IN ( SELECT DECODE ( scrnfail_rate, 0, -1, ROUND (LEVEL * 1 / (scrnfail_rate / 100)) - ROUND (1 / (2 * (scrnfail_rate / 100))) ) AS nno FROM DUAL WHERE NVL (scrnfail_rate, 0) > 0 CONNECT BY LEVEL <= ROUND(9 * scrnfail_rate / 100) ) It looks like Oracle 11g is ignoring where decode or even where clause in the subquery. This query should return two rows as it does on Oracle 9i, but results ORA-01476: divisor is equal to zero on Oracle 11g EE 11.2.0.1.0 - 64bit. Can anyone help? Thanks!

    Read the article

  • I want to be able to derive from a class internally, but disallow class in other assemblies to derive from the class

    - by Rokke
    Hej I have the following setup: Assembly 1 public abstract class XX<T> : XX where T: YY { } public abstract class XX {} Assembly 2 public class ZZ : YY {} public class ZZFriend : XX<ZZ> {} I use this feature in reflection when in YY: public class YY { public Type FindFriend { return GetType().Assembly.GetTypes().FirstOrDefault( t => t.BaseType != null && t.BaseType.IsGenericType && typeof(XX).IsAssignableFrom(t) && t.BaseType.GetGenericArguments().FirstOrDefault() == GetType()); } } I would like do disallow inheritance of the non generic class XX like: public class ZZFriend: XX {} Alternatively, I need a method like (that can be used in the reflection in YY.FindFrind()): public Type F(Type t) { return GetTypeThatIsGeneric(XX, Type genericTypeParameter); } That can be used in YY as: Typeof(XX<ZZ) == F(typeof(GetType()) Hope that makes sense... Thanks in advance Søren Rokkedal

    Read the article

  • Which web site gives the most accurate indication of a programmer's capabilities?

    - by Jerry Coffin
    If you were hiring programmers, and could choose between one of (say) the top 100 coders on topcoder.com, or one of the top 100 on stackoverflow.com, which would you choose? At least to me, it would appear that topcoder.com gives a more objective evaluation of pure ability to solve problems and write code. At the same time, despite obvious technical capabilities, this person may lack any hint of social skills -- he may be purely a "lone coder", with little or no ability to help/work with others, may lack mentoring ability to help transfer his technical skills to others, etc. On the other hand, stackoverflow.com would at least appear to give a much better indication of peers' opinion of the coder in question, and the degree to which his presence and useful and helpful to others on the "team". At the same time, the scoring system is such that somebody who just throws up a lot of mediocre (or even poor answers) will almost inevitably accumulate a positive total of "reputation" points -- a single up-vote (perhaps just out of courtesy) will counteract the effects of no fewer than 5 down-votes, and others are discouraged (to some degree) from down-voting because they have to sacrifice their own reputation points to do so. At the same time, somebody who makes little or no technical contribution seems unlikely to accumulate a reputation that lands them (even close to) the top of the heap, so to speak. So, which provides a more useful indication of the degree to which this particular coder is likely to be useful to your organization? If you could choose between them, which set of coders would you rather have working on your team?

    Read the article

  • How do you price your work?

    - by Dr.Kameleon
    Well, let me explain : This has really been an issue for me, for such a long time. And what is worse - since coding is something I simply ADORE (I would definitely do it, even if there was no payment involved whatsoever..) - is that I always end up feeling somewhat awkward... Anyway... So, here's the deal : You start working on a project, you may have something in your mind, and even if you're lucky enough and the client needs no "cost estimates" beforehand, sooner or later you'll face the ultimate dilemma of pricing your own work. So, how do YOU do it? By estimating the time you put into it? (obviously, this is not exact, 'coz perhaps a more capable coder will need much less time for the very same thing than a not-so-competent coder + even the very same coder may not "perform" equally at all times) By the Lines of code you've written? (obviously, this is not a measure either : a 10-line script that does exactly the same with a 1000-line script is, at least for me, "better") By taking into account the level of complexity of the project and, perhaps, how specialised the subject is? By taking into account other factors? (e.g. the value of the project for your customer)

    Read the article

  • How to convert an NSArray of NSManagedObjects to NSData

    - by carok
    Hi, I'm new to Objective C and was wondering if anyone can help me. I am using core data with a sqlite database to hold simple profile objects which have a name and a score attribute (both of which are of type NSString). What I want to do is fetch the profiles and store them in an NSData object, please see my code below: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"GamerProfile" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES]; NSArray *sortDecriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDecriptors]; [sortDescriptor release]; [sortDecriptors release]; NSError *error; NSArray *items = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error]; NSData *data = [NSKeyedArchiver archivedDataWithRootObject:items]; [self SendData:data]; [fetchRequest release]; When I run the code I'm getting the error "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[GamerProfile encodeWithCoder:]: unrecognized selector sent to instance 0x3f4b530'" I presume I have to add an encodeWithCoderClass to my core data NSManagedObject object (GamerProfile) but I'm not sure how to do this even after reading the documentation, My attempt at doing this is below. I'm not sure if I'm going along the right lines with this as get a warning stating "NSManagedObject" may not respond to '-encodeWithCoder'" I would really, really appreciate it if someone could point me in the right direction!! Thanks C Here is the code for my GamerProfile (CoreData NSManagedObject Object) with my attempt at adding an encodeWithCoder method... Header File #import <CoreData/CoreData.h> @interface GamerProfile : NSManagedObject <NSCoding> { } @property (nonatomic, retain) NSString * GamerScore; @property (nonatomic, retain) NSString * Name; - (void)encodeWithCoder:(NSCoder *)coder; @end Code File #import "GamerProfile.h" @implementation GamerProfile @dynamic GamerScore; @dynamic Name; - (void)encodeWithCoder:(NSCoder *)coder { [super encodeWithCoder:coder]; [coder encodeObject:GamerScore forKey:@"GamerScore"]; [coder encodeObject:Name forKey:@"Name"]; }

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >