Daily Archives

Articles indexed Tuesday March 23 2010

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

  • An interesting case of delete and destructor (C++)

    - by Viet
    I have a piece of code where I can call destructor multiple times and access member functions even the destructor was called with member variables' values preserved. I was still able to access member functions after I called delete but the member variables were nullified (all to 0). And I can't double delete. Please kindly explain this. Thanks. #include <iostream> using namespace std; template <typename T> void destroy(T* ptr) { ptr->~T(); } class Testing { public: Testing() : test(20) { } ~Testing() { printf("Testing is being killed!\n"); } int getTest() const { return test; } private: int test; }; int main() { Testing *t = new Testing(); cout << "t->getTest() = " << t->getTest() << endl; destroy(t); cout << "t->getTest() = " << t->getTest() << endl; t->~Testing(); cout << "t->getTest() = " << t->getTest() << endl; delete t; cout << "t->getTest() = " << t->getTest() << endl; destroy(t); cout << "t->getTest() = " << t->getTest() << endl; t->~Testing(); cout << "t->getTest() = " << t->getTest() << endl; //delete t; // <======== Don't do it! Double free/delete! cout << "t->getTest() = " << t->getTest() << endl; return 0; }

    Read the article

  • Quality gets worse

    - by Hopery
    I have bunch of flash videos and am adding my brand to all of them. The problem is quality gets worse. I am doing with this command: ffmpeg -i /input.flv -vhook "/usr/loca/vhook/drawtext.so -f /usr/share/fonts/somefont.ttf -x 5 -y 5 t MyBrand" -f flv -s 320x240 - | flvtools2 -U stdin /output.flv Please tell me what I am doing wrong. I need the same quality.

    Read the article

  • Can I create class properties during __new__ or __init__?

    - by 007brendan
    I want to do something like this. The _print_attr function is designed to be called lazily, so I don't want to evaluate it in the init and set the value to attr. I would like to make attr a property that computes _print_attr only when accessed: class Base(object): def __init__(self): for attr in self._edl_uniform_attrs: setattr(self, attr, property(lambda self: self._print_attr(attr))) def _print_attr(self, attr): print attr class Child(Base): _edl_uniform_attrs = ['foo', 'bar'] me = Child() me.foo me.bar #output: #"foo" #"bar"

    Read the article

  • Singleton pattern in C++

    - by skydoor
    I have a question about the singleton pattern. I saw two cases concerning the static member in the singleton class. First it is an object, like this class CMySingleton { public: static CMySingleton& Instance() { static CMySingleton singleton; return singleton; } // Other non-static member functions private: CMySingleton() {} // Private constructor ~CMySingleton() {} CMySingleton(const CMySingleton&); // Prevent copy-construction CMySingleton& operator=(const CMySingleton&); // Prevent assignment }; One is an pointer, like this class GlobalClass { int m_value; static GlobalClass *s_instance; GlobalClass(int v = 0) { m_value = v; } public: int get_value() { return m_value; } void set_value(int v) { m_value = v; } static GlobalClass *instance() { if (!s_instance) s_instance = new GlobalClass; return s_instance; } }; What's the difference between the two cases? Which one is correct?

    Read the article

  • add/remove items in a list

    - by Jam
    I'm trying to create a player who can add and remove items from their inventory. I have everything working, I just have 1 small problem. Every time it prints the inventory, 'None' also appears. I've been messing with it to try and remove that, but no matter what I do, 'None' always appears in the program! I know I'm just missing something simple, but I can't figure it out for the life of me. class Player(object): def __init__(self, name, max_items, items): self.name=name self.max_items=max_items self.items=items def inventory(self): for item in self.items: print item def take(self, new_item): if len(self.items)<self.max_items: self.items.append(new_item) else: print "You can't carry any more items!" def drop(self, old_item): if old_item in self.items: self.items.remove(old_item) else: print "You don't have that item." def main(): player=Player("Jimmy", 5, ['sword', 'shield', 'ax']) print "Max items:", player.max_items print "Inventory:", player.inventory() choice=None while choice!="0": print \ """ Inventory Man 0 - Quit 1 - Add an item to inventory 2 - Remove an item from inventory """ choice=raw_input("Choice: ") print if choice=="0": print "Good-bye." elif choice=="1": new_item=raw_input("What item would you like to add to your inventory?") player.take(new_item) print "Inventory:", player.inventory() elif choice=="2": old_item=raw_input("What item would you like to remove from your inventory?") player.drop(old_item) print "Inventory:", player.inventory() else: print "\nSorry, but", choice, "isn't a valid choice." main() raw_input("Press enter to exit.")

    Read the article

  • .gitignore for Visual Studio Projects and Solutions

    - by Martin Aatmaa
    Which files should I include in .gitignore when using Git in conjunction with Visual Studio Solutions (.sln) and Projects? Community Wiki: #OS junk files Thumbs.db *.DS_Store #Visual Studio files *.obj *.exe *.pdb *.user *.aps *.pch *.vspscc *.vssscc *_i.c *_p.c *.ncb *.suo *.tlb *.tlh *.bak *.cache *.ilk *.log *.lib *.sbr *.sdf ipch/ obj/ [Bb]in [Dd]ebug*/ [Rr]elease*/ #Tooling _ReSharper*/ [Tt]est[Rr]esult* #Project files [Bb]uild/

    Read the article

  • Decent simple SQL Server client

    - by John
    Hi, does anyone know of a very simple SQL Server client tool - that does the same basic functions as Management Studio (i.e. choose a database and run a query - doesn't need an Object Explorer, or anything fancy)? Ideally it would be great to have a single exe or zip file version that I could take around on a USB key - anything to avoid installing the full set of SQL Server client tools all the time! Thanks, John

    Read the article

  • Python.expat can't parse XML file with bad symbols. How to go around?

    - by culebrón
    I'm trying to parse an XML file with expat, and here's the line where I get bad token exception: <tag k="name" v="???????????????????????????????????????????????????????????????????" /> xml.parsers.expat.ExpatError: not well-formed (invalid token): line 610127, column 37 The symbols in hex look like: \xd1? Seems like someone wrote this string (Russian alfabet) hitting backspace a few times. I set parser.returns_unicode = True, but this didn't help. The 1st line is <?xml version="1.0" encoding="UTF-8"?>. I work with a bz2 file. (bz2.BZ2File) How can I parse the file?

    Read the article

  • How dangerous can javascript be?

    - by CrazyJugglerDrummer
    I have recently started using noscript (in addition to ABP). It took a little while to get used to it and can occasionally require some clicking when visiting a new site to investigate why the site's not working and where I need to allow javascript from. Is the extra security worth it? Some of the controversy is discussed here. I suppose it boils down to a matter of whether javascript is a genuine threat to your computer or not. Any thoughts on this?

    Read the article

  • How to use Windows live contacts api to allow users to import contacts

    - by AlfaTeK
    I can't find a good, simple tutorial on how to achieve this in PHP / Javascript. Basically the same thing FB has where the users specifies their hotmail account and then gives permission to FB to access their contacts. As the API seems to have changed most tutorials simply don't work like: http://livecontactsphp.codeplex.com/ which doesn't get the contacts (but authenticates and gets permission from user)

    Read the article

  • Need MySQL RLIKE expression to exclude certain strings ending in particular characters...

    - by user299508
    So I've been working with RLIKE to pull some data in a new application and mostly enjoying it. To date I've been using RLIKE queries to return 3 types of results (files, directories and everything). The queries (and example results) follow: **All**: SELECT * FROM public WHERE obj_owner_id='test' AND obj_namespace RLIKE '^user/test/public/[-0-9a-z_./]+$' ORDER BY obj_namespace user/test/public/a-test/.comment user/test/public/a-test/.delete user/test/public/directory/ user/test/public/directory/image.jpg user/test/public/index user/test/public/site-rip user/test/public/site-rip2 user/test/public/test-a user/test/public/widget-test **Files**: SELECT * FROM public WHERE obj_owner_id='test' AND obj_namespace RLIKE '^user/test/public/[-0-9a-z_./]+[-0-9a-z_.]+$' ORDER BY obj_namespace user/test/public/a-test/.comment user/test/public/a-test/.delete user/test/public/directory/image.jpg user/test/public/index user/test/public/site-rip user/test/public/site-rip2 user/test/public/test-a user/test/public/widget-test **Directories**: SELECT * FROM public WHERE obj_owner_id='test' AND obj_namespace RLIKE '^user/test/public/[-0-9a-z_./]+/$' ORDER BY obj_namespace user/test/public/directory/ This works well for the above 3 basic scenarios but under certain situations I'll be including special 'suffixes' I'd like to be excluded from the results of queries (without having to resort to PHP functions to do it). A good example of such a string would be: user/test/public/a-test/.delete That data (there are more rows then just obj_namespace) is considered deleted and in the Files and All type queries I'd like it to be omitted within the expression if possible. Same goes for the /.comments and all such meta data will always be in the same format: /.[sometext] I'd hoped to use this feature extensively throughout my application, so I'm hoping there might be a very simple answer. (crosses fingers) Anyway, thanks as always for any/all responses and feedback.

    Read the article

  • Quality gets worse

    - by HOpety
    I have bunch of flash videos and am adding my brand to all of them. The problem is quality gets worse. I am doing with this command: ffmpeg -i /input.flv -vhook "/usr/loca/vhook/drawtext.so -f /usr/share/fonts/somefont.ttf -x 5 -y 5 t MyBrand" -f flv -s 320x240 - | flvtools2 -U stdin /output.flv Please tell me what I am doing wrong. I need the same quality.

    Read the article

  • Visual Studio 2010 Team Explorer

    - by Sruly
    I just installed VS2010 and I want to connect to TFS, But I don't have any team explorer options. I searched for Team Explorer and I found this link that states that Team Explorer comes preinstalled in VS2010 Team Suit. I downloaded VS2010 Pro and don't have team explorer and can't find it anywhere. Any ideas? Tips? Thanks

    Read the article

  • Dismissing a modal view in horizontal orientation?

    - by Sheehan Alam
    I have a modal view that is presented and dismissed fine when my device is in vertical orientation. I have problems when my modal view is presented in the vertical orientation, but dismissed in horizontal orientation. The entire app switches back to vertical orientation automatically. How can I ensure that if I am in horizontal orientation, the view should dismiss properly?

    Read the article

  • RhinoMocks AAA Syntax

    - by Bill Campbell
    Hi, I've spent a good part of the day trying to figure out why a simple RhinoMocks test doesn't return the value I'm setting in the return. I'm sure that I'm just missing something really simple but I can't figure it out. Here's my test: [TestMethod] public void CopyvRAFiles_ShouldCallCopyvRAFiles_ShouldReturnTrue2() { FileInfo fi = new FileInfo(@"c:\Myprogram.txt"); FileInfo[] myFileInfo = new FileInfo[2]; myFileInfo[0] = fi; myFileInfo[1] = fi; var mockSystemIO = MockRepository.GenerateMock<ISystemIO>(); mockSystemIO.Stub(x => x.GetFilesForCopy("c:")).Return(myFileInfo); mockSystemIO.Expect(y => y.FileCopyDateCheck(@"c:\Myprogram.txt", @"c:\Myprogram.txt")).Return("Test"); CopyFiles copy = new CopyFiles(mockSystemIO); List<string> retValue = copy.CopyvRAFiles("c:", "c:", new AdminWindowViewModel(vRASharedData)); mockSystemIO.VerifyAllExpectations(); } I have an interface for my SystemIO class I'm passing in a mock for that to my CopyFiles class. I'm setting an expectation on my FileCopyDatCheck method and saying that it should Return("Test"). When I step through the code, it returns a null insteaed. Any ideas what I'm missing here? Here's my CopyFiles class Method: public List<string> CopyvRAFiles(string currentDirectoryPath, string destPath, AdminWindowViewModel adminWindowViewModel) { string fileCopied; List<string> filesCopied = new List<string>(); try { sysIO.CreateDirectoryIfNotExist(destPath); FileInfo[] files = sysIO.GetFilesForCopy(currentDirectoryPath); if (files != null) { foreach (FileInfo file in files) { fileCopied = sysIO.FileCopyDateCheck(file.FullName, destPath + file.Name); filesCopied.Add(fileCopied); } } //adminWindowViewModel.CheckFilesThatRequireSystemUpdate(filesCopied); return filesCopied; } catch (Exception ex) { ExceptionPolicy.HandleException(ex, "vRAClientPolicy"); Console.WriteLine("{0} Exception caught.", ex); ShowErrorMessageDialog(ex); return null; } } I would think that "fileCopied" would have the Return value set by the Expect. The GetFilesForCopy returns the two files in myFileInfo. Please Help. :) thanks in advance!

    Read the article

  • How to stop Quicktime movie in web page from auto loading?

    - by Liam
    I have two quicktime movie files embedded in one web page. I have set autoplay="false" to prevent them both from playing at the same time, but they still load at the same time. Can I prevent them from loading until the user clicks the play button? autohref="false" is supposed to do this but it does not seem to work. Apple's documentation for the EMBED element

    Read the article

  • Broadcast-style Bluetooth using Sockets on the iPhone?

    - by Kyle
    Is there any way to open a broadcast bluetooth socket, take a listen and send replies? I want a proper peer to peer system where I broadcast and listen for broadcasts in an area. That way, variable clients can mingle. Is this possible? My theory is this: If GameKit can sit around wasting 25 seconds of the users time whilst having access to a broadcast socket, can't I? Or, must I be in kernel mode for such access? I'm not really sure where the proper bluetooth headers are as well. Thanks for reading!

    Read the article

  • Glassfish war lifecycle question

    - by Robot
    What is the proper way to redeploy a new version of a running app in glassfish? I have a WAR running, and I've made changes. I thought doing an undeploy + deploy might be the right thing, but glassfish (v3) often crashes when I undeploy. What' the proper way to redeploy a running app in glassfish?

    Read the article

  • why my code error,about serve the static file using django..

    - by zjm1126
    my settings.py: DIRNAME = os.path.dirname(__file__) STATIC_DOC_ROOT = os.path.join(DIRNAME, 'media') MEDIA_URL = '/media/' my urls.py: def google(request): return render_to_response('a.html',context_instance=RequestContext(request)) urlpatterns = patterns('', (r'^$',google), (r'^media/(?P<path>.*)$', 'django.views.static.serve',{'document_root':settings.STATIC_DOC_ROOT,'show_indexes': True}), ) and my a.html is: <script type="text/javascript" src="/media/jquery-1.4.2.js"></script> <script type="text/javascript"> alert($) </script> but,it can't defiend the '$' why ? thanks

    Read the article

  • Providing or Filtering assemblies when registering areas for an ASP.NET MVC 2.0 application

    - by HackedByChinese
    I have a large application that currently exists as a hybrid of WebForms and MVC 2.0. Startup of my application is dreadful, and the culprit is primarily because of the AreaRegistration.RegisterAllAreas call. More specifically, that it is using the System.Web. Compilation.BuildManager.GetReferencedAssemblies to enumerate all types in assemblies directly referenced by the application and test them to see if they derive from AreaRegistration. Unfortunately, I have a number of third-party assemblies that happen to be quite extensive, so this initial load can be pretty bad. I'd have much better results if I could tell it which assemblies to look for AreaRegistrations, or even register areas manually for the time being. I can gather up all the internals of AreaRegistration to create and invoke the registration, but I'm just curious if others have had and worked around this issue.

    Read the article

  • Why does my C++ LinkedList method print out the last word more than once?

    - by Anthony Glyadchenko
    When I call the cmremoveNode method in my LinkedList from outside code, I get an EXC_BAD_ACCESS. FIXED: But now the last word using the following test code gets repeated twice: #include <iostream> #include "LinkedList.h" using namespace std; int main (int argc, char * const argv[]) { ctlinkList linkMe; linkMe.cminsertNode("The"); linkMe.cminsertNode("Cat"); linkMe.cminsertNode("Dog"); linkMe.cminsertNode("Cow"); linkMe.cminsertNode("Ran"); linkMe.cminsertNode("Pig"); linkMe.cminsertNode("Away"); linkMe.cmlistList(); cout << endl; linkMe.cmremoveNode("The"); linkMe.cmremoveNode("Cow"); linkMe.cmremoveNode("Away"); linkMe.cmlistList(); return 0; } LinkedList code: /* * LinkedList.h * Lab 6 * * Created by Anthony Glyadchenko on 3/22/10. * Copyright 2010 __MyCompanyName__. All rights reserved. * */ #include <stdio.h> #include <iostream> #include <fstream> #include <iomanip> using namespace std; class ctNode { friend class ctlinkList ; // friend class allowed to access private data private: string sfileWord ; // used to allocate and store input word int iwordCnt ; // number of word occurrances ctNode* ctpnext ; // point of Type Node, points to next link list element }; class ctlinkList { private: ctNode* ctphead ; // initialized by constructor public: ctlinkList () { ctphead = NULL ; } ctNode* gethead () { return ctphead ; } string cminsertNode (string svalue) { ctNode* ctptmpHead = ctphead ; if ( ctphead == NULL ) { // allocate new and set head ctptmpHead = ctphead = new ctNode ; ctphead -> ctpnext = NULL ; ctphead -> sfileWord = svalue ; } else { //find last ctnode do { if ( ctptmpHead -> ctpnext != NULL ) ctptmpHead = ctptmpHead -> ctpnext ; } while ( ctptmpHead -> ctpnext != NULL ) ; // fall thru found last node ctptmpHead -> ctpnext = new ctNode ; ctptmpHead = ctptmpHead -> ctpnext ; ctptmpHead -> ctpnext = NULL; ctptmpHead -> sfileWord = svalue ; } return ctptmpHead -> sfileWord ; } string cmreturnNode (string svalue) { return NULL; } string cmremoveNode (string svalue) { int counter = 0; ctNode *tmpHead = ctphead; if (ctphead == NULL) return NULL; while (tmpHead->sfileWord != svalue && tmpHead->ctpnext != NULL){ tmpHead = tmpHead->ctpnext; counter++; } do{ tmpHead->sfileWord = tmpHead->ctpnext->sfileWord; tmpHead = tmpHead->ctpnext; } while (tmpHead->ctpnext != NULL); return tmpHead->sfileWord; } string cmlistList () { string tempList; ctNode *tmpHead = ctphead; if (ctphead == NULL){ return NULL; } else{ while (tmpHead != NULL){ cout << tmpHead->sfileWord << " "; tempList += tmpHead->sfileWord; tmpHead = tmpHead -> ctpnext; } } return tempList; } }; Why is this happening?

    Read the article

  • Invalid Memory Acess for JavaFX ScrollBar on Snow-Leopard

    - by Mike Caron
    I created the following JavaFX script, which when run, generates an Invalid memory access on Snow-Leopard. What is it about javafx.scene.control.ScrollBar that is causing a memory failure? Stage { title: "Scroll View" scene: Scene { content: [ ScrollBar { min: 0 max: 100 value: 0 blockIncrement: 10 vertical: false } ] } resizable: false } I'm using whatever JavaFX (at least 1.2) that comes with NetBeans 6.8: Product Version: NetBeans IDE 6.8 (Build 200912041610) Java: 1.6.0_17; Java HotSpot(TM) 64-Bit Server VM 14.3-b01-101 System: Mac OS X version 10.6.2 running on x86_64; MacRoman; en_US (nb)

    Read the article

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