pointers

std::vector of functions

Hi all I want a std::vector to contain some functions, and that more functions can be added to it in realtime. All the functions will have a prototype like this: void name(SDL_Event *event); I know how to make an array of functions, but how do I make a std::vector of functions? I've tried this: std::vector<( *)( SDL_Event *)> functio...

Another C pointer Question

The following code : int *a; *a = 5; will most likely result in a segmentation fault and I know why. The following code : int a; *a = 5; won't even compile. (gcc says : invalid type argument of unary *). Now, a pointer is simply an integer, which is used for storing an address. So, why should it be a problem if I say : *a = 5...

C array pointer question

I thought that an array variable cannot be changed in C, i.e. the base address of an array is unchangeable, but the following code contradicts my assumption : #include <stdlib.h> #include <stdio.h> void changeArray(int **a) { *a = malloc(sizeof(int)); } int main() { int a[10]; a[0] = 1; printf("%d\n",a[0]); changeArr...

Unhandled exception when dereferencing char pointer in Visual C++ 2008

I'm trying to do some classic C development in Visual C++ 2008 that will modify the characters of a string like so: void ModifyString(char *input) { // Change first character to 'a' *input = 'a'; } I'm getting a unhandled exception when I try to change a character. It seems like I could do this in Visual Studio 6 or using gcc, bu...

Objective-C - How to implement an array of pointers in a method declaration

Ok, if you take a look at my two previous posts (Link #2 in particular), I would like to ask an additional question pertaining to the same code. In a method declaration, I am wanting to define one of the parameters as a pointer to an array of pointers, which point to feat_data. I'm sort of at a loss of where to go and what to do except t...

Need help with this snippet of code with pointers.

Im new to pointers (just began learning) and came across the following code snippet and needed to predict the output. My answer was 220 but was told its wrong. Could someone tell me the correct output and please explain why. using System; class pointer { public static void Main() { int ptr1=0; int* ptr2=&ptr1; *ptr2=220; ...

Pointers, primitives, and properties in Objective-C classes

I really need some clarification — I have a few questions and I'm all mixed up right now. Here is a simple class interface: #import <UIKit/UIKit.h> @interface Car : NSObject{ NSInteger carID; NSString *carName; } @property (nonatomic, assign) NSInteger carID; @property (nonatomic, copy) NSString * carName; @end Why is carI...

Indirection operator * - Noob question.

Possible Duplicate: Placement of the asterisk in Objective-C Could someone please shed some light as I am a bit confused as to the proper use of the indirection operator. Example: NSAutoReleasePool * pool = [[NSAutoReleasPool alloc] init]; MyAwesomeClass *awesomeClass; So as I see them; are they just stylistic differences on...

array of integers vs. pointer to integer in c++

If I have int x[10] and int *y, how can I tell the difference between the two? I have two ideas: sizeof() is different. &x has different type --- int (*p)[10] = &x works but not int **q = &x. Any others? In some template library code, I need to determine whether a pointer is a "real" pointer or degenerated from an array...

C++ pointer issue

Hi everyone, So I'm learning C++ at the moment and I'm trying to work things out with pointers. Could anybody explain the following scenario: bool testFalse = false; //testFalse = false bool *thisIsFalse = &testFalse; //value of address of thisIsFalse shows that the address contains false bool shouldBeFalse = &thisIsFalse; //shouldBeF...

Achieving Interface functionality in C++

A big reason why I use OOP is to create code that is easily reusable. For that purpose Java style interfaces are perfect. However, when dealing with C++ I really can't achieve any sort of functionality like interfaces... at least not with ease. I know about pure virtual base classes, but what really ticks me off is that they force me in...

How to write a NSMutableArray of a struct type that also includes NSMutableArray inside of it?

I was wondering if there is any sample code out there for objective-C for implementing a NSMutableArray of type struct. Inside, I need there to be 2 mutable arrays (via NSMutableArray also) declared in the struct. All the code samples in my book show me how to make an array of defined size via C array syntax (with the brackets), but I do...

creating a vector of pointers that point to more vectors

Hello, I am trying to create a vector that contains pointers, each pointer points to another vector of a type Cell which I have made using a struct. The for loop below allows me to let the user define how many elements there are in the vector of pointers. Here's my code: vector< vector<Cell>* > vEstore(selection); for (int t=0; t<selec...

why does this code give a access violation when run on msdev ?

while(*a++ = *b++){} where a and b are valid char pointers. ...

Understanding double pointer in doubly linked list in C

Hi, I have an exam tomorrow and I was trying to understand this doubly linked list example that the instructor placed on the class website but I'm having a hard time understanding a bit of it... Here's the code: #include <stdio.h> #include <stdlib.h> typedef struct dl { int key; float value; struct dl *next; struct dl...

Pointers to variables?

Is it possible to have pointers to data variables? I know I can have, say, pointers to strings e.g. char *str[n] and I can perform a 'for' loop over those pointers to retrieve the strings ... str[i] where i is the index counter. If I have some data e.g. char var1; int var2; char var3; and I wanted to get data from stdin I might use ...

use operators in templates in c++

I am trying to implement a List class using pointers and am trying to implement a function LOCATE(T x) where T is for the template and returns the first position of the element x if found, else returns last position + 1. My functions code is template<class T> int List<T>::locate(T n) const { int size = end(); Node<T> * p = head_...

C++: member pointer initialised?

Code sample should explain things: class A { B* pB; C* pC; D d; public : A(int i, int j) : d(j) { pC = new C(i, "abc"); } // note pB is not initialised, e.g. pB(NULL) ... }; Obviously pB should be initialised to NULL explicitly to be safe (and clear), but, as it stands, what is the value of p...

Simulating Pointers in Python

I'm trying to cross compile an in house language(ihl) to Python. One of the ihl features is pointers and references that behave like you would expect from C or C++. For instance you can do this: a = [1,2]; // a has an array b = &a; // b points to a *b = 2; // derefernce b to store 2 in a print(a); // outputs 2 print(*b); ...

pointer to an array

Hi, I have a pointer to an array and i am unable to access the members of the array.To make it more precise,plz see the code below: int struc[2] = {6,7}; int (*Myval)[2]; Myval =&struc; Now the Myval is pointing to the start of the array and upon dereferencing the pointer we would get the 1st element o...