pointers

C++ pointer to objects

In C++ do you always have initialize a pointer to an object with the new keyword? Or can you just have this too: MyClass *myclass; myclass->DoSomething(); I thought this was a pointer allocated on the stack instead of the heap, but since objects are normally heap allocated, I think my theory is probably faulty?? Please advice. ...

C++ finding pointer errors

Hello! I am currently on a project which has been buggy for a long while, now I suspect, among other things, that there is pointer errors in the code. The program is written in native C++ using COM and uses out-of-process COM servers. Can anybody give me some tips as how one would go about finding these errors? Is there specific th...

NSMutableArray filled with pointers

I know this question was already asked in the past, but i am really confused and can't get out of it. i have got 9 pointers to IB objects declared like: IBOutlet UIButton *but1; IBOutlet UIButton *but2; .... NSMutableArray *buttons; declared properties: @property (nonatomic,retain) IBOutlet UIButton *but1; ...

Help with data retrieval MACRO

Hello, given the following structure: struct nmslist_elem_s { nmptr data; struct nmslist_elem_s *next; }; typedef struct nmslist_elem_s nmslist_elem; Where: typedef void* nmptr; Is it possible to write a MACRO that retrieves the data from the element and cast it to the right type: MACRO(type, element) that expands to *((ty...

C++ pointers on example

I have a sample code : #include <iostream> #include <conio.h> using namespace std; int main () { int firstvalue = 5, secondvalue = 15; int * p1, * p2; p1 = &firstvalue; p2 = &secondvalue; cout << "1.p1: " << p1 << ", p2: " << p2 << endl; cout << "1.*p1: " << *p1 << ", *p2: " << *p2 << endl; *p1 = 10; cout << "2.p1: ...

Obj-C: Passing pointers to initialized classes in other classes

Hey all. I initialized a class in my singleton called DataModel. Now, from my UIViewController, when I click a button, I have a method that is trying to access that class so that I may add an object to one of its dictionaries. My get/set method passes back the pointer to the class from my singleton, but when I am back in my UIViewCont...

char ** nargv being empty but do not know why

Hi, I am trying to do something quite easy: fill an char** with arguments I want to use in a execvp call in C. This is how I am doing: if(argc >=1) { *nargv = "--action"; while(argc--) { printf("nargv1 => %s \t argv1 => %s \n", *nargv, *argv); *++nargv = *argv++; printf("nargv2 =>...

Void pointer cast C++ and GTK

See this GTK callback function: static gboolean callback(GtkWidget *widget, GdkEventButton *event, gpointer *data) { AnyClass *obj = (AnyClass*) data; // using obj works } (please note the gpointer* on the data). And then the signal is connected using: AnyClass *obj2 = new AnyClass(); gtk_signal_connect(/*GTK params (...)*/, ...

c Pointer to pointer, or passing list to functions

Hi, I am new to c programming. Could anyone please tell me what's wrong with the following program? typedef struct Person_s { int age; char name[40]; } Person_t; int process_list(int *countReturned, Person_t **p_list) { Person_t *rowPtr=0; //the actual program will fethc data from DB int count =1; if(!((*p_list) = ...

Using C++ is a Linked-List implementation without using pointers possible or not?

My question is very simple, can one using C++, implment a link-list data structure without using pointers (next nodes)? To further qualify my question, I'm mean can one create a Linked-List data structure using only class instantiations. A common node definition might be like so: template<typename T> struct node { T t; node<T>* n...

Converting c pointer types

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 a...

C++: Copying to dereferenced pointer...

Hi. I currently have a weird problem with a program segfaulting but im not able to spot the error. I think the problem boils down to this. struct S {int a; vector<sometype> b;} S s1; // fill stuff into a and b S* s2 = new S(); *s2 = s1; Could it be that the final copying is illegal in some way? Im really confused right now... Thanks ...

build IB pointers to existing objects in interface builder without iboutlet

is there any function to init an UIButton with a button from Interface Builder without using IBOutlets? i have 20 buttons in my view and i need to modify their image without declaring 20 pointers. i think it would be something like: UIButton *but=[[UIButton alloc] initWithButtonTag:20]; [but setImage:[UIImage imageNamed:@"myIm...

C++: Cannot convert from foo& to foo*

I have a method: odp(foo& bar); I'm trying to call it: foo baz; odp(&baz); I get a compiler error: error C2664: "odp" cannot convert parameter 1 from 'foo *' to 'foo &' What am I doing wrong? Aren't I passing in a reference to baz? UPDATE: Perhaps I have a misconception about the relationship between pointers and references. I ...

Initialize Pointer Through Function

I was browsing my teacher's code when I stumbled across this: Order* order1 = NULL; then order1 = order(customer1, product2); which calls Order* order(Customer* customer, Product* product) { return new Order(customer, product); } This looks like silly code. I'm not sure why, but the teacher initialized all pointers to NULL in...

pointer uchar* question in opencv vc++ 2008

img_hsv is a Mat element of an hsv image! when i give cout<<*img_hsv.data+10; it gives true value of the pixel ie 79 as output. but when i assign uchar * a=img_hsv.data+10; it gives me some other value... can you please explain me why is this the case? thanks! ...

How to pass a function in a function?

That's an odd title. I would greatly appreciate it if somebody could clarify what exactly I'm asking because I'm not so sure myself. I'm watching the Stanford videos on Programming Paradigms(that teacher is awesome) and I'm up to video five when he started doing this: void *lSearch( void* key, void* base, int elemSize, int n, int (*cmp...

How to queue and call actual methods (rather than immediately eval) in java?

There are a list of tasks that are time sensitive (but "time" in this case is arbitrary to what another program tells me - it's more like "ticks" rather than time). However, I do NOT want said methods to evaluate immediately. I want one to execute after the other finished. I'm using a linked list for my queue, but I'm not really sure how...

Help with pointers in Cocoa

I'm trying to make a simple calculator application in cocoa. The program hangs when I click on one of my buttons. I think I've traced the problem to the part of my controller that adds a digit to the end of the number currently on the display: - (void)updateNumber:(int)buttonClicked{ *self.activeNumberPointer = *self.activeNumberPoint...

C pointer initialization and dereferencing, what's wrong here?

This should be super simple, but I'm not sure why the compiler is complaining here. #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int *n = 5; printf ("n: %d", *n); exit(0); } Getting the following complaints: foo.c: In function ‘main’: foo.c:6: warning: initialization makes pointer from i...