Search Results

Search found 3592 results on 144 pages for 'pointer'.

Page 125/144 | < Previous Page | 121 122 123 124 125 126 127 128 129 130 131 132  | Next Page >

  • Importing a C DLL's functions into a C++ program

    - by bobobobo
    I have a 3rd party library that's written in C. It exports all of its functions to a DLL. I have the .h file, and I'm trying to load the DLL from my C++ program. The first thing I tried was surrounding the parts where I #include the 3rd party lib in #ifdef __cplusplus extern "C" { #endif and, at the end #ifdef __cplusplus } // extern "C" #endif But the problem there was, all of the DLL file function linkage looked like this in their header files: a_function = (void *)GetProcAddress(dll, "a_function"); While really a_function had type int (*a_function) (int *). Apparently MSVC++ compiler doesn't like this, while MSVC compiler does not seem to mind. So I went through (brutal torture) and fixed them all to the pattern typedef int (*_a_function) (int *); _a_function a_function ; Then, to link it to the DLL code, in main(): a_function = (_a_function)GetProcAddress(dll, "a_function"); This SEEMS to make the compiler MUCH, MUCH happier, but it STILL complains with this final set of 143 errors, each saying for each of the DLL link attempts: error LNK2005: _a_function already defined in main.obj main.obj Multiple symbol definition errors.. sounds like a job for extern! SO I went and made ALL the function pointer declarations as follows: function_pointers.h typedef int (*_a_function) (int *); extern _a_function a_function ; And in a cpp file: function_pointers.cpp #include "function_pointers.h" _a_function a_function ; ALL fine and dandy.. except for linker errors now of the form: error LNK2001: unresolved external symbol _a_function main.obj Main.cpp includes "function_pointers.h", so it should know where to find each of the functions.. I am bamboozled. Does any one have any pointers to get me functional? (Pardon the pun..)

    Read the article

  • Determining presence of prototype with correct return type

    - by R..
    Here's a random problem in C black magic I just came up with: Write a function that returns 1 if malloc has been prototyped to return a pointer type and 0 if malloc has a return type of int (either implicitly or due to wrong prototype), without invoking any implementation-defined or undefined behavior. I believe it's solvable, but I haven't worked out the solution. Note that calling the function cannot be necessary and in fact is not possible since calling a function with the incorrect prototype is undefined behavior. I have some ideas for ingredients but I think it makes for a better puzzle (and possibly more diverse ideas) if I leave them out for now. I don't need the solution for any immediate use, but it could be handy in configure scripts and such. Update: A better example of the usefulness (with strdup instead of malloc): #undef strdup #define strdup(x) (strdup_has_proto ? strdup((x)) : my_strdup((x))) i.e. being able to implement X_has_proto as an expression at the source level could be a portable way to use functions which a system might or might not have, and fall back on a local replacement, without needing any separate configure step.

    Read the article

  • My java program seems to be skipping over the try{}, executing the catch{} and then throwing a NullPointerException. What should I do?

    - by Matt Bolopue
    I am writing a program that calculates the number of words, syllables, and sentences in any given text file. I don't need help finding those numbers, however my program (which currently should only find the number of words in the text file) will not import the text file even when I type in the name of the file correctly. The text file is in the same folder as the source code. Instead it tells me every time that what I typed in has the wrong file extension (see my catch{}) and then proceeds to throw a null pointer. I am at a loss for what could be causing it. Any suggestions? import java.io.*; import java.util.*; public class Reading_Lvl_Calc { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int words = 0; String fileName; Scanner scan; Scanner keyread = new Scanner(System.in); System.out.println("Please enter a file name (or QUIT to exit)"); fileName = keyread.nextLine(); File doc = new File(fileName); //while(scan.equals(null)){ try { scan = new Scanner(doc); } catch(Exception e) { if(fileName.substring(fileName.indexOf(".")) != ".txt") System.out.println("I'm sorry, the file \"" + fileName + "\" has an invalid file extension."); else System.out.println("I am sorry, the file \"" + fileName + " \" cannot be found.\n The file must be in the same directory as this program"); scan = null; } // } while(scan.hasNext()){ words++; scan.next(); } System.out.println(words); } }

    Read the article

  • Deleting from 2 arrays of dictionaries

    - by Matt Winters
    I have an array of dictionaries loaded from a plist (below) called arrayHistory. <plist version="1.0"> <array> <dict> <key>item</key> <string>1</string> <key>result</key> <string>8.1</string> <key>date</key> <date>2009-12-15T19:36:59Z</date> </dict> ... </array> </plist> I filter this array based on 'item' so that a second array, arrayHistoryDetail has the same structure as arrayHistory but only contains e.g. 'item's equal to '1'. These detail items are successfully displayed in a tableView. I then want to select an item from the tableView, and delete it from the tableView data source, arrayHistoryDetail (line 2 in the code below) - works, then I want to delete the item from the tableView itself (line 3 in the code below) - also works. My problem is that I also need to delete it from the original arrayHistory, so I tried the following: created a temporary dictionary as an ivar: NSMutableDictionary *tempDict; @property (nonatomic, retain) NSMutableDictionary *tempDict; Then my thinking was to make a copy in line 1 and remove it from the original array in line 4. 1 tempDict = [arrayHistoryDetail objectAtIndex: indexPath.row]; 2 [arrayHistoryDetail removeObjectAtIndex: indexPath.row]; 3 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 4 [arrayHistory removeObject:tempDict]; Didn't work. Could someone please guide me in the right direction. I'm thinking that tempDict is a pointer and that removeObject needs a copy? I don't know. Thanks.

    Read the article

  • How can multiple variables be passed to a function cleanly in C?

    - by aquanar
    I am working on an embedded system that has different output capabilities (digital out, serial, analog, etc). I am trying to figure out a clean way to pass many of the variables that will control those functions. I don't need to pass ALL of them too often, but I was hoping to have a function that would read the input data (in this case from a TCP network), and then parse the data (IE, the 3rd byte contains the states of 8 of the digital outputs (according to which bit in that byte is high or low)), and put that into a variable where I can then use elsewhere in the program. I wanted that function to be separate from the main() function, but to do so would require passing pointers to some 20 or so variables that it would be writing to. I know I could make the variables global, but I am trying to make it easier to debug by making it obvious when a function is allowed to edit that variable, by passing it to the function. My best idea was a struct, and just pass a pointer to it, but wasn't sure if there was a more efficient way, especially since there is only really 1 function that would need to access all of them at once, while most others only require parts of the information that will be stored in this bunch of state variables. So anyway, is there a clean way to send many variables between functions at once that need to be edited?

    Read the article

  • Does implementing a Java class under an open-source library's package name constitutes a modificatio

    - by Minyu
    Greetings, I understand that this is not the best forum for getting legal advices. But I am still wondering if anybody has some experience around this topic, or can point me to relevant resources that explain it. I have tried to search it online but could not find clear answers. Assuming I am using a Java open-source library from "somecompany", specifically its entities in the "org.somecompany.somepackage". During development, I found that I need to access some of the internals of that package that are not exposed through its public interface. So I thought maybe creating my own classes under the same "org.somecompany.somepackage" name would make that easier. My question is: does this constitutes a modification of the open-source library? The fully qualified name of my classes look like "org.somecompany.somepackage.myclass". It does seem an "extension" of the original library, even though I am not modifying the original library source or binary. I am also not adding my classes to the open-source jar files. Any advice or pointer to resources will be appreciated!

    Read the article

  • Greasemonkey script, that creates Kineticjs drag and drop canvas over every website

    - by Michael Moeller
    I'd like to put a drag and drop canvas over every website I visit in Firefox. My Greasemonkey script puts a drag and drop canvas under every page: kinetic.user.js: // ==UserScript== // @name kineticjs_example // @description Canvas Drag and Drop // @include * // @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js // @require http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v4.7.2.min.js // ==/UserScript== var div = document.createElement( 'div' ); with( div ) { setAttribute( 'id', 'container' ); } // append at end document.getElementsByTagName( 'body' )[ 0 ].appendChild( div ); var stage = new Kinetic.Stage({ container: 'container', width: 1000, height: 1000 }); var layer = new Kinetic.Layer(); var rectX = stage.getWidth() / 2 - 50; var rectY = stage.getHeight() / 2 - 25; var box = new Kinetic.Rect({ x: rectX, y: rectY, width: 100, height: 50, fill: '#00D2FF', stroke: 'black', strokeWidth: 4, draggable: true }); // add cursor styling box.on('mouseover', function() { document.body.style.cursor = 'pointer'; }); box.on('mouseout', function() { document.body.style.cursor = 'default'; }); layer.add(box); stage.add(layer); How can I drag and drop this shape over the entire website?

    Read the article

  • Image on mouseover takes space on PageLoad.

    - by Ram
    Hello, I am trying to show an image on Mouseover and hide it on Mouseout. I am successful in mouseover and mouseout but the image is actually taking the space around the text though i have visibility as hidden.. The text is surrounded with the space of image but the image is displayed on mouseover. Here is the code: <td valign="middle" class="table_td td top" style="width: 347px"> <div id="Style16" style="position:relative; height:100%; left:50%; bottom:700%; visibility:hidden; border:solid 0px #CCC; padding:5px"><img src="images/window-decal-image.gif"></div> <span class="feature_text" style="cursor:pointer" onmouseover="ShowPicture('Style16',1)" onmouseout="ShowPicture('Style16',0)" id="a16">Storefront Window Decal</span> <span class="feature_text_small">(5"x3.5" double sided decal)</span></td> <script language="javascript" type="text/javascript"> function ShowPicture(id,Source) { var vis, elem; if (1 == Source) { vis = "visible"; } else if (0 == Source) { vis = "hidden"; } else { throw new RangeError("Unknown Flag"); } if (elem = document.getElementById(id)) { elem.style.visibility = vis; } else { throw new TypeError("Element with id '"+id+"' does not exist."); } return vis; } </script>

    Read the article

  • How can I hide this overlay element intelligently?

    - by inkedmn
    The site I'm working on has a collection of navigation elements across the top ("Products", "Company", etc.). When you mouse over the Products link, an overlay appears that shows a list of products with links to each. There's a small link at the top of the container that, when clicked, closes the container. All of this works as advertised. The client has asked that, once a user's mouse pointer is a sufficient distance from the overlay element, the overlay element would close (without them having to click the 'close' link). This element appears on multiple pages that have disparate content, so I'm afraid it won't be as simple as adding a mouseover listener to another single element within the page and have it work everywhere. My question, I suppose, is this: is there a relatively easy way to know when the mouse cursor is x pixels away from this container and trigger an event when this occurs? My other thought is that I could just find several elements on the page that fit this criteria and add mouseover listeners to each, but I'm assuming there's a more elegant way of handling this. Thanks in advance - and please let me know if more detail is needed.

    Read the article

  • can I store an id value in array of float type ?

    - by srikanth rongali
    I used, for(id value in values) to get the value from an NSArray. Now I want to store it in 2 dimensional float array[][]. When I try to assign the values to array it is giving error:incompatible types in assignment. I tried to cast the value but I got error: pointer value used where a floating point value was expected. I need to store the values in an 2 dimensional array . How can I make it ? Thank You. @implementation fromFileRead1 NSString *fileNameString; int numberOfEnemies, numberOfValues; -(id)init { if( (self = [super init]) ) { NSString *path = @"/Users/sridhar/Desktop/Projects/exampleOnFile2/enemyDetals.txt"; NSString *contentsOfFile = [[NSString alloc] initWithContentsOfFile:path]; NSArray *lines = [contentsOfFile componentsSeparatedByString:@"\n"]; numberOfEnemies = [lines count]; NSLog(@"The number of Lines: %d", numberOfEnemies); for (id line in lines) { NSLog(@"Line %@", line ); NSString *string1 = line; NSArray *split1 = [string1 componentsSeparatedByString:@","]; numberOfValues = [split1 count]; NSLog(@"The number of values in Row: %d", numberOfValues); for (id value in split1) { NSLog(@"value %@", value); float value1; value1 = [split1 objectAtIndex:2]); NSLog(@"VAlue of Value1 at index 2: %f", value1 ); } } } return self; } @end In enemyDetal.txt I have 1,3,3 2,3,2.8 10,2,1.6

    Read the article

  • Alignment for image display on hover works only in IE7?

    - by Ram
    Hello, I tried to display a image when a mouseover on text occurs. It works fine. And the alignment of the image should be shown such that the end of the image should be at the container. It works fine with the code shown below, Only in IE7. In everything, it gets chopped off.. What is wrong here? <td valign="middle" class="table_td td" style="width: 347px"> <span class="feature_text" style="cursor:pointer" onmouseover="ShowPicture('Style16',1)" onmouseout="ShowPicture('Style16',0)" id="a16"> Storefront Window Decal</span> <div id="Style16" style="position:relative;height:0px;left:50%;bottom:700%; visibility:hidden; border:solid 0px #CCC; padding:5px"> <img src="images/window-decal-image.gif"></div> <script language="javascript" type="text/javascript"> function ShowPicture(id,Source) { var vis, elem; if (1 == Source) { vis = "visible"; } else if (0 == Source) { vis = "hidden"; } else { throw new RangeError("Unknown Flag"); } if (elem = document.getElementById(id)) { elem.style.visibility = vis; } else { throw new TypeError("Element with id '"+id+"' does not exist."); } return vis; } </script> Can someone help me out. Thanks in advance!!

    Read the article

  • opening word document contailning macros using textarea

    - by avani-nature
    Hai frnds i am avani here,actually 1.i amhaving one word document which contains macros i wann to open it in textarea.. 2.i am able to open the word document which is not containing macros 3.i am not able to open the document which contains macros 4.i am using below code 5.please do help me anyone i am thinking its some what impossible { //echo $aud; $filename = 'C:/xampp/htdocs/mts/sites/default/files/a.doc'; //echo $filename; if(isset($_REQUEST['Save'])){ $somecontent = stripslashes($_POST['somecontent']); // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename) - Continue - "; fclose($handle); } else { echo "The file $filename is not writable"; } } else{ // get contents of a file into a string $handle = fopen($filename, "r"); $somecontent = fread($handle, filesize($filename)); $word = new COM("word.application") or die ("Could not initialise MS Word object."); $word-Documents-Open(realpath("$filename")); // Extract content. $somecontent = (string) $word-ActiveDocument-Content; //echo $somecontent; $word-ActiveDocument-Close(false); $word-Quit(); $word = null; unset($word); fclose($handle); } ? Edit file -------- ?

    Read the article

  • jquery simplemodal close wont work in firefox

    - by junkqwe
    I am using jquery.simplemodal 1.3.5 (i tried older versions) the close button doesnt close the modal in firefox (i tried IE and it work fine) this is the test page i am using: <html> <head> <title>Untitled Page</title> <style> #simplemodal-overlay { background-color:#000; cursor:wait; } #simplemodal-container a.modalCloseImg { background: url(../images/modal_close.png) no-repeat; width:25px; height:29px; display:inline; z-index:3200; position:absolute; top:15px; right:18px; cursor:pointer; } .modala { width: 372px; height: 206px; background: url(../images/modal.png) no-repeat; } </style> </head> <body> test page <script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> <script language="javascript" src="/include/jquery.simplemodal-1.3.5.js" type="text/javascript"></script> <script type="text/javascript"> $("body").click(function() { $.modal("<div class=\"modala\"><h1>SimpleModal</h1></div>", {overlayClose: true} ); }); </script> </body> </html> what can be the problem? is it a known problem with simplemodal and FF?

    Read the article

  • How to store <TR> id value in array, when I toggle?

    - by James123
    I am toggling 'tr.subCategory1'and its siblings .RegText. at the same time I am trying to store its ids in the array like this list_Visible_Ids[$(this).attr('id')] = $(this).css('display') != 'none' ? 1 : null; (When I collapsed I need store 'null' in array at its id place, If I expand I need store I need store 1 at its id place). But everytime alert($(this).css('display')) showing block. How can I handle this?. So When I collapsed or expanded it is storing 1 only. $(document).ready(function() { $('tr[@class^=RegText]').hide().children('td'); list_Visible_Ids = []; var idsString, idsArray; idsString = $('#myVisibleRows').val(); idsArray = idsString.split(','); $.each(idsArray, function() { if (this != "" || this != null) { $('#' + this).siblings('.RegText').toggle(); list_Visible_Ids[this] = 1; } }); $('tr.subCategory1') .css("cursor", "pointer") .attr("title", "Click to expand/collapse") .click(function() { $(this).siblings('.RegText').toggle(); $(this).siblings('.VolumeRegText').toggle(); //alert($(this).css('display')) list_Visible_Ids[$(this).attr('id')] = $(this).css('display') != 'none' ? 1 : null; }); $('#form1').submit(function() { idsString = ''; for (var index in list_Visible_Ids) { idsString += (idsString != '' ? ',' : '') + index; } $('#myVisibleRows').val(idsString); form1.submit(); }); });

    Read the article

  • Adding and sorting a linked list in C

    - by user1202963
    In my assignment, I have to write a function that takes as arguments a pointer to a "LNode" structure and an integer argument. Then, I have to not only add that integer into the linked list, but also put place it so that the list is in proper ascending order. I've tried several various attempts at this, and this is my code as of posting. LNode* AddItem(LNode *headPtr, int newItem) { auto LNode *ptr = headPtr; ptr = malloc(sizeof(LNode)); if (headPtr == NULL) { ptr->value = newItem; ptr->next = headPtr; return ptr; } else { while (headPtr->value > newItem || ptr->next != NULL) { printf("While\n"); // This is simply to let me know how many times the loop runs headPtr = headPtr->next; } ptr->value = newItem; ptr->next = headPtr; return ptr; } } // end of "AddItem" When I run it, and try to insert say a 5 and then a 3, the 5 gets inserted, but then the while loop runs once and I get a segmentation fault. Also I cannot change the arguments as it's part of a skeletal code for this project. Thanks to anyone who can help. If it helps this is what the structure looks like typedef struct LNode { int value; struct LNode *next; } LNode;

    Read the article

  • Resource allocation and automatic deallocation

    - by nabulke
    In my application I got many instances of class CDbaOciNotifier. They all share a pointer to only one instance of class OCIEnv. What I like to achieve is that allocation and deallocation of the resource class OCIEnv will be handled automatically inside class CDbaOciNotifier. The desired behaviour is, with the first instance of class CDbaOciNotifier the environment will be created, after that all following notifiers use that same environment. With the destruction of the last notifier, the environment will be destroyed too (call to custom deleter). What I've got so far (using a static factory method to create notifiers): #pragma once #include <string> #include <memory> #include "boost\noncopyable.hpp" class CDbaOciNotifier : private boost::noncopyable { public: virtual ~CDbaOciNotifier(void); static std::auto_ptr<CDbaOciNotifier> createNotifier(const std::string &tnsName, const std::string &user, const std::string &password); private: CDbaOciNotifier(OCIEnv* envhp); // All notifiers share one environment static OCIEnv* m_ENVHP; // Custom deleter static void freeEnvironment(OCIEnv *env); OCIEnv* m_envhp; }; CPP: #include "DbaOciNotifier.h" using namespace std; OCIEnv* CDbaOciNotifier::m_ENVHP = 0; CDbaOciNotifier::~CDbaOciNotifier(void) { } CDbaOciNotifier::CDbaOciNotifier(OCIEnv* envhp) :m_envhp(envhp) { } void CDbaOciNotifier::freeEnvironment(OCIEnv *env) { OCIHandleFree((dvoid *) env, (ub4) OCI_HTYPE_ENV); *env = null; } auto_ptr<CDbaOciNotifier> CDbaOciNotifier::createNotifier(const string &tnsName, const string &user, const string &password) { if(!m_ENVHP) { OCIEnvCreate( (OCIEnv **) &m_ENVHP, OCI_EVENTS|OCI_OBJECT, (dvoid *)0, (dvoid * (*)(dvoid *, size_t)) 0, (dvoid * (*)(dvoid *, dvoid *, size_t))0, (void (*)(dvoid *, dvoid *)) 0, (size_t) 0, (dvoid **) 0 ); } //shared_ptr<OCIEnv> spEnvhp(m_ENVHP, freeEnvironment); ...got so far... return auto_ptr<CDbaOciNotifier>(new CDbaOciNotifier(m_ENVHP)); } I'd like to avoid counting references (notifiers) myself, and use something like shared_ptr. Do you see an easy solution to my problem?

    Read the article

  • Array Assignment

    - by Mahesh
    Let me explain with an example - #include <iostream> void foo( int a[2], int b[2] ) // I understand that, compiler doesn't bother about the // array index and converts them to int *a, int *b { a = b ; // At this point, how ever assignment operation is valid. } int main() { int a[] = { 1,2 }; int b[] = { 3,4 }; foo( a, b ); a = b; // Why is this invalid here. return 0; } Is it because, array decays to a pointer when passed to a function foo(..), assignment operation is possible. And in main, is it because they are of type int[] which invalidates the assignment operation. Doesn't a,b in both the cases mean the same ? Thanks. Edit 1: When I do it in a function foo, it's assigning the b's starting element location to a. So, thinking in terms of it, what made the language developers not do the same in main(). Want to know the reason.

    Read the article

  • Nested bind expressions

    - by user328543
    This is a followup question to my previous question. #include <functional> int foo(void) {return 2;} class bar { public: int operator() (void) {return 3;}; int something(int a) {return a;}; }; template <class C> auto func(C&& c) -> decltype(c()) { return c(); } template <class C> int doit(C&& c) { return c();} template <class C> void func_wrapper(C&& c) { func( std::bind(doit<C>, std::forward<C>(c)) ); } int main(int argc, char* argv[]) { // call with a function pointer func(foo); func_wrapper(foo); // error // call with a member function bar b; func(b); func_wrapper(b); // call with a bind expression func(std::bind(&bar::something, b, 42)); func_wrapper(std::bind(&bar::something, b, 42)); // error // call with a lambda expression func( [](void)->int {return 42;} ); func_wrapper( [](void)->int {return 42;} ); return 0; } I'm getting a compile errors deep in the C++ headers: functional:1137: error: invalid initialization of reference of type ‘int (&)()’ from expression of type ‘int (*)()’ functional:1137: error: conversion from ‘int’ to non-scalar type ‘std::_Bind(bar, int)’ requested func_wrapper(foo) is supposed to execute func(doit(foo)). In the real code it packages the function for a thread to execute. func would the function executed by the other thread, doit sits in between to check for unhandled exceptions and to clean up. But the additional bind in func_wrapper messes things up...

    Read the article

  • C++ reinterpret cast ?

    - by Ian
    I would like to cast one object of the class PointsList to another object Points3DList (and vice versa) where: template <class T> class PointsList { protected: std::vector <Point <T> *> points; //Only illustration, not possible with templaes }; and template <class T> class Points3DList { protected: std::vector <Point3D<T> *> points; //Only illustration, not possible with templaes }; Between Point and Point3D there is no relationship (inheritance nor composition)... template <class T> class Point { protected: T x; T y; }; template <class T> class Point3D { protected: T x; T y; T z; }; What do you think about conversion Points3DList <T> *pl3D = new Points3DList <T> (); ... PointsList <T> *pl = reinterpret_cast < PointList <T> * > ( pl3D ); where pl3D represents pointer to Points3DList object.. Can reinterpret_cast be used in this case or it is better to create a conversion function? Data model in this case can not be changed...

    Read the article

  • Android thread handler NullPointerException

    - by Realn0whereman
    So this null pointer is confusing me. I believe it is a scope issue. My main activity looks like this: public class App extends Activity { ProgressDialog progressDialog; ProgressThread progressThread; Then inside of the oncreate I do this: ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage("Fetching Images..."); ProgressThread progressThread = new ProgressThread(handler,mImageIds,mImages); progressThread.start(); progressDialog.show(); THEN inside progressThread which is a separate class I do mHandler.sendMessage(mHandler.obtainMessage()); Now up until this point i believe it behaves as it should. I have my handler hanging out in class scope right underneath my oncreate final Handler handler = new Handler() { public void handleMessage(Message msg){ progressDialog.hide(); progressThread.interrupt(); } }; The program thinks that progressDialog and progressThread are declared, but are null. Why would they be null if I instantiate in my oncreate.

    Read the article

  • How can a B-tree node be represented?

    - by chronodekar
    We're learning B-trees in class and have been asked to implement them in code. The teacher has left choice of programming language to us and I want to try and do it in C#. My problem is that the following structure is illegal in C#, unsafe struct BtreeNode { int key_num; // The number of keys in a node int[] key; // Array of keys bool leaf; // Is it a leaf node or not? BtreeNode*[] c; // Pointers to next nodes } Specifically, one is not allowed to create a pointer to point to the structure itself. Is there some work-around or alternate approach I could use? I'm fairly certain that there MUST be a way to do this within the managed code, but I can't figure it out. EDIT: Eric's answer pointed me in the right direction. Here's what I ended up using, class BtreeNode { public List<BtreeNode> children; // The child nodes public static int MinDeg; // The Minimum Degree of the tree public bool IsLeaf { get; set; } // Is the current node a leaf or not? public List<int> key; // The list of keys ... }

    Read the article

  • [C++] Parent-Child scheme

    - by rubenvb
    I'm writing a class that holds a pointer to a parent object of the same type (think Qt's QObject system). Each object has one parent, and the parent should not be destroyed when a child is destroyed (obviously). class MyClass { public: MyClass(const MyClass* ptr_parent): parent(parent){}; ~MyClass(){ delete[] a_children; }; private: const MyClass* ptr_parent; // go to MyClass above MyClass* a_children; // go to MyClass below size_t sz_numChildren; // for iterating over a_children } (Excuse my inline coding, it's only for brevity) Will destroying the "Master MyClass" take care of all children? No child should be able to kill it's parent, because I would then have pointers in my main program to destroyed objects, correct? Why might you ask? I need a way to "iterate" through all subdirectories and find all files on a platform independent level. The creation of this tree will be handled by native API's, the rest won't. Is this a good idea to start with? Thanks!

    Read the article

  • Boost shared_ptr use_count function

    - by photo_tom
    My application problem is the following - I have a large structure foo. Because these are large and for memory management reasons, we do not wish to delete them when processing on the data is complete. We are storing them in std::vector<boost::shared_ptr<foo>>. My question is related to knowing when all processing is complete. First decision is that we do not want any of the other application code to mark a complete flag in the structure because there are multiple execution paths in the program and we cannot predict which one is the last. So in our implementation, once processing is complete, we delete all copies of boost::shared_ptr<foo>> except for the one in the vector. This will drop the reference counter in the shared_ptr to 1. Is it practical to use shared_ptr.use_count() to see if it is equal to 1 to know when all other parts of my app are done with the data. One additional reason I'm asking the question is that the boost documentation on the shared pointer shared_ptr recommends not using "use_count" for production code.

    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

  • OS-independent Inter-program communication between Python and C

    - by Gyppo
    I have very little idea what I'm doing here, I've never done anything like this before, but a friend and I are writing competing chess programs and they need to be able to communicate to each other. He'll be writing mainly in C, the bulk of mine will be in Python, and I can see a few options: Alternately write to a temp file, or successive temp files. As the communication won't be in any way bulky this could work, but seems like an ugly work-around to me, the programs will have to keep checking for change/new files, it just seems ugly. Find some way of manipulating pipes i.e. mine.py| ./his . This seems like a bit of a dead end. Use sockets. But I don't know what I'd be doing, so could someone give me a pointer to some reading material? I'm not sure if there are OS-independent, language independent methods. Would there have to be some kind of supervisor server program to administrate? Use some kind of HTML protocol, which seems like overkill. I don't mind the programs having to run on the same machine. What do people recommend, and where can I start reading?

    Read the article

< Previous Page | 121 122 123 124 125 126 127 128 129 130 131 132  | Next Page >