Search Results

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

Page 15/144 | < Previous Page | 11 12 13 14 15 16 17 18 19 20 21 22  | Next Page >

  • C++ smart pointer for non-object type?

    - by Brian
    Hi, I'm trying to use smart pointers such as auto_ptr, shared_ptr. However, I don't know how to use it in this situation. CvMemStorage *storage = cvCreateMemStorage(); ... use the pointer ... cvReleaseMemStorage(&storage); I'm not sure, but I think that the storage variable is just malloc'ed memory, not object. Is there a way to use the smart pointers for the storage variable? Thank you.

    Read the article

  • Comparison between pointer and integer (cocoa)

    - by Cal S
    Hi, I'm just learning cocoa (coming from C#) but I'm getting a strange error for something that seems really simple... (charsSinceLastUpdate=36) #import "CSMainController.h" @implementation CSMainController //global vars int *charsSinceLastUpdate = 0; NSString *myString = @"Hello world"; // - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { ... } //other functions - (void)textDidChange:(NSNotification *)aNotification { NSLog(@"charsSinceLastUpdate=%i",charsSinceLastUpdate); if (charsSinceLastUpdate>=36) { // <- THIS line returns the error: Comparison between pointer and integer charsSinceLastUpdate=0; [statusText setStringValue:@"Will save now!"]; } else { charsSinceLastUpdate++; [statusText setStringValue:@"Not saving"]; } } //my functions - (void)showNetworkErrorAlert:(BOOL)showContinueWithoutSavingOption { ... } // @end Any help would be appreciated, thanks!

    Read the article

  • Forked Function not assigning pointer

    - by Luke Mcneice
    In the code below I have a function int GetTempString(char Query[]); calling it in main works fine. However, when calling the function from a fork the fork hangs (stops running, no errors, no output) before this line: pch = strtok (Query," ,"); the printf shows that the pointer to pch is null. Again this only happens when the fork is executing it. What am I doing doing wrong? int main() { if((Timer =fork())==-1) printf("Timer Fork Failed"); else if(Timer==0) { while(1) { sleep(2); GetTempString("ch 1,2,3,4"); } } else { //CODE GetTempString("ch 1,2,3,4"); } } int GetTempString(char Query[]) { char * pch; printf("DEBUG: '%s'-'%d'\n",Query,pch); pch = strtok (Query," ,");//* PROBLEM HERE* //while loop for strtok... return 1; }

    Read the article

  • storing an integral value in a pointer variable while declaration

    - by benjamin button
    int main() { int *d=0; printf("%d\n",*d); return 0; } this works fine. >cc legal.c > ./a.out 0 if i change the statement int *d=0; to int *d=1; i see the error. cc: "legal.c", line 6: error 1522: Cannot initialize a pointer with an integer constant other than zero. so its obvious that it will allow only zero.i want to know what happens inside the memory when we do this int *d=0 which is making it valid syntax. I am just asking this out of curiosity!

    Read the article

  • Dangling pointer

    - by viswanathan
    Does this piece of code lead to dangling pointer. My guess is no. class Sample { public: int *ptr; Sample(int i) { ptr = new int(i); } ~Sample() { delete ptr; } void PrintVal() { cout << "The value is " << *ptr; } }; void SomeFunc(Sample x) { cout << "Say i am in someFunc " << endl; } int main() { Sample s1 = 10; SomeFunc(s1); s1.PrintVal(); }

    Read the article

  • C++ run error: pointer being freed was not allocated

    - by Dale Reves
    I'm learning c++ and am working on a program that keeps giving me a 'pointer being freed was not allocated' error. It's a grocery store program that inputs data from a txt file, then user can enter item# & qty. I've read through similar questions but what's throwing me off is the 'pointer' issue. I would appreciate if someone could take a look and help me out. I'm using Netbeans IDE 7.2 on a Mac. I'll just post the whole piece I have so far. Thx. #include <iostream> #include <fstream> #include <string> #include <vector> using namespace std; class Product { public: // PLU Code int getiPluCode() { return iPluCode; } void setiPluCode( int iTempPluCode) { iPluCode = iTempPluCode; } // Description string getsDescription() { return sDescription; } void setsDescription( string sTempDescription) { sDescription = sTempDescription; } // Price double getdPrice() { return dPrice; } void setdPrice( double dTempPrice) { dPrice = dTempPrice; } // Type..weight or unit int getiType() { return iType; } void setiType( int iTempType) { iType = iTempType; } // Inventory quantity double getdInventory() { return dInventory; } void setdInventory( double dTempInventory) { dInventory = dTempInventory; } private: int iPluCode; string sDescription; double dPrice; int iType; double dInventory; }; int main () { Product paInventory[21]; // Create inventory array Product paPurchase[21]; // Create customer purchase array // Constructor to open inventory input file ifstream InputInventory ("inventory.txt", ios::in); //If ifstream could not open the file if (!InputInventory) { cerr << "File could not be opened" << endl; exit (1); }//end if int x = 0; while (!InputInventory.eof () ) { int iTempPluCode; string sTempDescription; double dTempPrice; int iTempType; double dTempInventory; InputInventory >> iTempPluCode >> sTempDescription >> dTempPrice >> iTempType >> dTempInventory; paInventory[x].setiPluCode(iTempPluCode); paInventory[x].setsDescription(sTempDescription); paInventory[x].setdPrice(dTempPrice); paInventory[x].setiType(iTempType); paInventory[x].setdInventory(dTempInventory); x++; } bool bQuit = false; //CREATE MY TOTAL VARIABLE HERE! int iUserItemCount; do { int iUserPLUCode; double dUserAmount; double dAmountAvailable; int iProductIndex = -1; //CREATE MY SUBTOTAL VARIABLE HERE! while(iProductIndex == -1) { cout<<"Please enter the PLU Code of the product."<< endl; cin>>iUserPLUCode; for(int i = 0; i < 21; i++) { if(iUserPLUCode == paInventory[i].getiPluCode()) { dAmountAvailable = paInventory[i].getdInventory(); iProductIndex = i; } } //PLU code entry validation if(iProductIndex == -1) { cout << "You have entered an invalid PLU Code."; } } cout<<"Enter the quantity to buy.\n"<< "There are "<< dAmountAvailable << "available.\n"; cin>> dUserAmount; while(dUserAmount > dAmountAvailable) { cout<<"That's too many, please try again"; cin>>dUserAmount; } paPurchase[iUserItemCount].setiPluCode(iUserPLUCode);// Array of objects function calls paPurchase[iUserItemCount].setdInventory(dUserAmount); paPurchase[iUserItemCount].setdPrice(paInventory[iProductIndex].getdPrice()); paInventory[iProductIndex].setdInventory( paInventory[iProductIndex].getdInventory() - dUserAmount ); iUserItemCount++; cout <<"Are you done purchasing items? Enter 1 for yes and 0 for no.\n"; cin >> bQuit; //NOTE: Put Amount * quantity for subtotal //NOTE: Put code to update subtotal (total += subtotal) // NOTE: Need to create the output txt file! }while(!bQuit); return 0; }

    Read the article

  • C Class Instance from Void Pointer using Ctypes

    - by g.d.d.c
    I've got a C DLL that exposes a handful of methods that return void pointers to a Class like so: void *GetLicense() { static AppLicenseImpl ipds_; return (void *) &ipds_; } In C++, after loading the DLL, I'd do this to work with it: typedef void *(* FPGetLicense)(); GetLicense_ = (FPGetLicense)GetAddress("GetLicense"); license_ = (AppLicense *) GetLicense_(); license_->GetApplicationStatus(); // Load data so that other calls don't fail I can't figure out how to parallel that in Python. This gets me the pointer: d = ctypes.cdll.LoadLibrary('license.dll') d.GetLicense.restype = ctypes.c_void_p p = d.GetLicense() # returns ptr loc, something like 8791433660848L But I obviously can't call p.GetApplicationStatus() in Python. Does anyone have a suggestion on how I'd instantiate that Class the rest of the way in Python so that I can call GetApplicationStatus()?

    Read the article

  • Avoid incompatible pointer warning when dealing with double-indirection

    - by fnawothnig
    Assuming this program: #include <stdio.h> #include <string.h> static void ring_pool_alloc(void **p, size_t n) { static unsigned char pool[256], i = 0; *p = &pool[i]; i += n; } int main(void) { char *str; ring_pool_alloc(&str, 7); strcpy(str, "foobar"); printf("%s\n", str); return 0; } ... is it possible to somehow avoid the GCC warning test.c:12: warning: passing argument 1 of ‘ring_pool_alloc’ from incompatible pointer type test.c:4: note: expected ‘void **’ but argument is of type ‘char **’ ... without casting to (void**) (or simply disabling the compatibility checks)? Because I would very much like to keep compatibility warnings regarding indirection-level...

    Read the article

  • Void pointer values comparing C++

    - by user2962977
    My actual question is it really possible to compare values contained in two void pointers, when you actually know that these values are the same type? For example int. void compVoids(void *firstVal, void *secondVal){ if (firstVal < secondVal){ cout << "This will not make any sense as this will compare addresses, not values" << endl; } } Actually I need to compare two void pointer values, while outside the function it is known that the type is int. I do not want to use comparison of int inside the function. So this will not work for me as well: if (*(int*)firstVal > *(int*)secondVal) Any suggestions? Thank you very much for help!

    Read the article

  • storing an integer constant other than zero in a pointer variable

    - by benjamin button
    int main() { int *d=0; printf("%d\n",*d); return 0; } this works fine. >cc legal.c > ./a.out 0 if i change the statement int *d=0; to int *d=1; i see the error. cc: "legal.c", line 6: error 1522: Cannot initialize a pointer with an integer constant other than zero. so its obvious that it will allow only zero.i want to know what happens inside the memory when we do this int *d=0 which is making it valid syntax. I am just asking this out of curiosity!

    Read the article

  • Converting c pointer types

    - by bobbyb
    I have a c pointer to a structre type called uchar4 which looks like { uchar x; uchar y; uchar z; uchar w; } I also have data passed in as uint8*. I'd like to create a uchar* pointing to the data at the uint8* so I've tried doing this: uint8 *data_in; uchar4 *temp = (uchar4*)data_in; However, the first 8 bytes always seem to be wrong. Is there another way of doing this?

    Read the article

  • pointer delegate in STL set.

    - by ananth
    hi. Im kinda stuck with using a set with a pointer delegate. my code is as follows: void Graph::addNodes (NodeSet& nodes) { for (NodeSet::iterator pos = nodes.begin(); pos != nodes.end(); ++pos) { addNode(*pos); } } Here NodeSet is defined as: typedef std::set NodeSet; The above piece of code works perfectly on my windows machine, but when i run the same piece of code on a MAC, it gives me the following error: no matching function for call to 'Graph::addNode(const boost::shared_ptr&)' FYI, Node_ptr is of type: typedef boost::shared_ptr Node_ptr; can somebody plz tell me why this is happening?

    Read the article

  • Object pointer value as key into dictionary

    - by Ranking Stackingblocks
    I want to use the object's reference value as a key into a dictionary, as opposed to a copy of value of the object. So, I essentially want to store an object associated with a particular instance of another object in a dictionary and retrieve that value later. Is this possible? Is it completely against the idea of NSDictionary? I can tell that I am probably approaching this the wrong way because the dictionary wants me to implement NSCopying on the object itself, which doesn't really make sense in terms of what I'm doing. I can see that what I should really be doing is wrapping the pointer value, but that seems a little mad. Advice would be appreciated.

    Read the article

  • inode_operations , warning: initialization from incompatible pointer type

    - by djTeller
    Hi everyone, I'm trying to compile a simple Kernel program that read and write from a proc file. I'm trying to set permission to that file by overriding the permission fp in inode_operations struct (.permission) static int module_permission(struct inode *inode, int op, struct nameidata *foo) { . . . } static struct inode_operations Inode_Ops_4_Our_Proc_File = { .permission = module_permission, /* check for permissions */ }; Our_Proc_File->proc_iops = &Inode_Ops_4_Our_Proc_File; For some reason, when I compile this i get - warning: initialization from incompatible pointer type on the following line: .permission = module_permission, /* check for permissions */ Any idea how to solve this? Thanks!

    Read the article

  • C Structure Pointer Problem

    - by Halo
    I have this struct; #define BUFSIZE 10 struct shared_data { pthread_mutex_t th_mutex_queue; int count; int data_buffer_allocation[BUFSIZE]; int data_buffers[BUFSIZE][100]; }; and I want to allocate one of the data_buffers for a process, for that purpose I execute the following function; int allocate_data_buffer(int pid) { int i; for (i = 0; i < BUFSIZE; i++) { if (sdata_ptr->data_buffer_allocation[i] == NULL) { sdata_ptr->data_buffer_allocation[i] = pid; return i; } } return -1; } but the compiler warns me that I'm comparing pointer to a value. When I put a & in front of sdata_ptr it calms down but I'm not sure if it will work. Isn't what I wrote above supposed to be true?

    Read the article

  • Function template accepting nothing less than a bidirectional iterator or a pointer

    - by san
    I need a function template that accepts two iterators that could be pointers. If the two arguments are random_access iterators I want the return type to be an object of std::iterator<random_access_iterator_tag, ...> type else a std::iterator<bidirectional_iterator_tag, ...> type. I also want the code to refuse compilation if the arguments are neither a bidirectional iterator, nor a pointer. I cannot have dependency on third party libraries e.g. Boost Could you help me with the signature of this function so that it accepts bidirectional iterators as well as pointers, but not say input_iterator, output_iterator, forward_iterators. One partial solution I can think of is the following template<class T> T foo( T iter1, T iter2) { const T tmp1 = reverse_iterator<T>(iter1); const T tmp2 = reverse_iterator<T>(iter2); // do something } The idea is that if it is not bidirectional the compiler will not let me construct a reverse_iterator from it.

    Read the article

  • NULL pointer dereference in C

    - by user554125
    hey ive got this piece of code. It dereferences a null pointer here. But then there is an and with unsigned int. I really dont understand the whole part. Can someone explain the output.?? struct hi { long a; int b; long c; }; int main() { struct hi ob={3,4,5}; struct hi *ptr=&ob; int num= (unsigned int) & (((struct hi *)0)->b); printf("%d",num); printf("%d",*(int *)((char *)ptr + (unsigned int) & (((struct hi *)0)->b))); } The o/p i get is 44 .But how does it work?

    Read the article

  • assignment makes pointer from integer without a cast

    - by mrblippy
    hi, i am trying to make a linked list and create some methods. but i am getting the error assignment makes pointer from integer without a cast. #include <stdio.h> #include <stdlib.h> #include "students.h" node_ptr create(void) { node_ptr students = (node_ptr) malloc(sizeof(struct node)); students->ID = 0; students->name = NULL; students->next = NULL; return students; } void insert_in_order(int n, node_ptr list) { node_ptr before = list; node_ptr new_node = (node_ptr) malloc(sizeof(struct node)); new_node->ID = n;//error is here i think while(before->next && (before->next->ID < n)) { before = before->next; } new_node->next = before->next; before->next = new_node; }

    Read the article

  • Syncronizing indices of function pointer table to table contents

    - by Thomas Matthews
    In the embedded system I'm working on, we are using a table of function pointers to support proprietary Dynamic Libraries. We have a header file that uses named constants (#define) for the function pointer indices. These values are used in calculating the location in the table of the function's address. Example: *(export_table.c)* // Assume each function in the table has an associated declaration typedef void (*Function_Ptr)(void); Function_Ptr Export_Function_Table[] = { 0, Print, Read, Write, Process, }; Here is the header file: *export_table.h* #define ID_PRINT_FUNCTION 1 #define ID_READ_FUNCTION 2 #define ID_WRITE_FUNCTION 3 #define ID_PROCESS_FUNCTION 4 I'm looking for a scheme to define the named constants in terms of their location in the array so that when the order of the functions changes, the constants will also change. (Also, I would like the compiler or preprocessor to calculate the indices to avoid human mistakes like typeo's.)

    Read the article

  • how do you find the exact variable of a null pointer exception

    - by OVERTONE
    I've been at this one for a bit now. I've got a null pointer exception so im guessing somethings not been initialized. AdminMessages.inbox1.setText(messageRsetArray[0]); thats my code where its targetting. but i cant find what inside it hasnt been initiazed. AdminMessages is a class which contains a JTextField called inbox1, messageRsetArray is an array which has taken variables from an array. also inbox1 is static. i coulndt get the getters and setter to work. i know its bad practice though.

    Read the article

  • custom ListView --Null pointer exception

    - by raghs
    this code throws a Null pointer exception. It was thrown by getChildAt(i). The getCount() returns the number of items in listView. But getChildAt(i) returns only if item is present in current list view. For example in a scrollable list view assume that there are 20 items. The getCount() returns 20. But getChildAt(20) returns null. Because it doesnot fit in listview. How to solve this problem?? int i,j=object.getCount(); View v=getListView(); CheckBox chk=null; for(i=0;i<j;i++) { chk=((CheckBox)((ViewGroup) v).getChildAt(i).findViewById(R.id.checkBox1)); if(chk.isChecked()) { //download the contents to specific folder in sd card } }

    Read the article

  • Dynamic creation of a pointer function in c++

    - by Liberalkid
    I was working on my advanced calculus homework today and we're doing some iteration methods along the lines of newton's method to find solutions to things like x^2=2. It got me thinking that I could write a function that would take two function pointers, one to the function itself and one to the derivative and automate the process. This wouldn't be too challenging, then I started thinking could I have the user input a function and parse that input (yes I can do that). But can I then dynamically create a pointer to a one-variable function in c++. For instance if x^2+x, can I make a function double function(double x){ return x*x+x;} during run-time. Is this remotely feasible, or is it along the lines of self-modifying code?

    Read the article

  • fetchedResultsController objectAtIndexPath: i "Passing argument 1 of objectAtIndexPath: makes pointer from integer without cast

    - by cocos2dbeginner
    NSMutableDictionary* dict = [[NSMutableDictionary alloc] init]; id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:0]; for (int i; i<[sectionInfo numberOfObjects]; i++) { NSManagedObject *o = [self.fetchedResultsController objectAtIndexPath:i]; [dict setObject:[[o valueForKey:@"frontCard"] description] forKey:@"frontCard"]; [dict setObject:[[o valueForKey:@"flipCard"] description] forKey:@"flipCard"]; } In this line NSManagedObject *o = [self.fetchedResultsController objectAtIndexPath:i]; i get this warning: warning: passing argument 1 of 'objectAtIndexPath:' makes pointer from integer without a cast

    Read the article

  • Pointer to another classs as a property

    - by arjacsoh
    Why I receive an error when I try to create a property to another class through a pointer like that: #ifndef SQUARE_H #define SQUARE_H #include <string> //using namespace std; #include "Player.h" class Square { public: Square(int); void process(); protected: int ID; Player* PlayerOn; <--- }; #endif and the Player class is : #ifndef PLAYER_H #define PLAYER_H #include <string> //using namespace std; #include "Square.h" class Player { public: Player(int,int); // ~Player(void); int playDice(); private: int ID; int money; }; #endif I receive: syntax error missing ; before * (on the declaration of Player* PlayerOn;) and missing type specifier (on the same line...)

    Read the article

  • null pointer exception on list.add

    - by Eric
    I've been working on this one error for a few hours so I thought I'd pick the brains of some pros. I am getting a null pointer exception at the modelData.add(i, es) method. I know from debugging that es isn't null. I'm really confused, thanks. public class EventTableModel extends AbstractTableModel { //private int rowCount = 0; protected List<EventSeat> modelData; private static final int COLUMN_COUNT = 3; private Event e; Event j = GUIpos.m; int i = 1; public EventTableModel(Event e) { this.e = e; try { System.out.println(modelData); for (EventSeat es : e.getEventSeats()) { modelData.add(i, es); i++; } } catch (DataException ex) { Logger.getLogger(EventTableModel.class.getName()).log(Level.SEVERE, null, ex); } }

    Read the article

< Previous Page | 11 12 13 14 15 16 17 18 19 20 21 22  | Next Page >