pointers

how to use iterator in c++?

I'm trying to calculate distance between 2 points. The 2 points I stored in a vector in c++: (0,0) and (1,1). I'm supposed to get results as 0 1.4 1.4 0 but the actual result that I got is 0 1 -1 0 I think there's something wrong with the way I use iterator in vector. Could somebody help? I posted the code below. typedef struct po...

Access violation of member of pointer object

So I am coding this client/server program. This code is from the client side. The client has an instance of an object mpqs_sieve *instance_; The reason I make it as a pointer is, that mpqs_sieve only has a constructor that takes 3 arguments, and I want to instantiate it at a later point in time. The client first gets some data from t...

c# Wrapper to native c++ code, wrapping a parameter which is a pointer to an array

Hi, I have the following simple DLL in c++ un-managed code; extern "C" __declspec(dllexport) void ArrayMultiplier(float (*pointerArray)[3], int scalar, int length); void ArrayMultiplier(float (*pointerArray)[3], int scalar, int length) { for (int i = 0 ; i < length ; length++) { for (int j = 0; j < 3; j++) { ...

C++ Pointer Objects vs. Non Pointer Objects

Possible Duplicate: Why would you ever want to allocate memory on the heap rather than the stack? Test2 *t2 = new Test2(); t2->test(); Test2 t3; t3.test(); Why would I want to create a pointer object of type Test2? Why not just do non pointer version of Test2? Why would I want to do pointer objects? Found answer here: Wh...

Typcast a null pointer to char*

Suppose I have a char* elem that is supposed to hold a char**, such that elem[0] = char**, elem[1...m]= <more chars>. Is there a way I can put a null ptr within char* elem? When I try to set elem = NULL, it gives me a type error because NULL is an int. Any help would be greatly appreciated! ...

pointers to functions

I have two basic Cpp tasks, but still I have problems with them. First is to write functions mul1,div1,sub1,sum1, taking ints as arguments and returning ints. Then I need to create pointers ptrFun1 and ptrFun2 to functions mul1 and sum1, and print results of using them. Problem starts with defining those pointers. I thought I was doing i...

How can I free all allocated memory at once?

Here is what I am working with: char* qdat[][NUMTBLCOLS]; char** tdat[]; char* ptr_web_data; // Loop thru each table row of the query result set for(row_index = 0; row_index < number_rows; row_index++) { // Loop thru each column of the query result set and extract the data for(col_index = 0; col_index < numb...

complex arguments for function

My task is to create function funCall taking four arguments : pointer for 2d array of ints that stores pairs of numbers variable int maintaining number of numbers in 2d array pointer for table of pointers to functions int variable storing info about number of pointers to functions I was thinking about something like this : typedef i...

dynamically created arrays

My task consists of two parts. First I have to create globbal char array of 100 elements, and insert some text to it using cin. Afterwards calculate amount of chars, and create dedicated array with the length of the inputted text. I was thinking about following solution : char[100]inputData; int main() { cin >> inputData >> endl;...

Initializing and accessing a pointer from an array of pointers

Suppose I have the following: void **Init(int numElems) { //What is the best way to intialize 'ptrElems' to store an array of void *'s? void **ptrElems = malloc(numElems * sizeof(void *)); return ptrElems; } //What is the best way to return a pointer pointing at the index passed as a parameter? void **GetPtr(void **ptrElems, i...

Using a Function returning apointer as LValue

Why cant I used a function returning a pointer as a lvalue? For example this one works int* function() { int* x; return x; } int main() { int* x = function(); x = new int(9); } but not this int* function() { int* x; return x; } int main() { int* x; function() = x; } While I can use a pointer variab...

Pointer-Safe Objects?

Would it be smart to have a vector in an object with a list of pointers that point to it? This way when the object is deleted, it could delete all the pointers pointing to it to prevent a null-pointer exception? ...

Translating C pointer code example to Delphi pointer syntax.

I am working with a binary file structure. The code example for reading the data is in C, and I need to read it in Delphi. I hasten to add I have no C programming experience. Given the following typedef struct { uchar ID, DataSource; ushort ChecksumOffset; uchar Spare, NDataTypes; ushort Offset [256]; } HeaderType; ... typedef stru...

Building 16 bit os - character array not working

Hi. I am building a 16 bit operating system. But character array does not seem to work. Here is my example kernel code: asm(".code16gcc\n"); void putchar(char); int main() { char *str = "hello"; putchar('A'); if(str[0]== 'h') putchar('h'); return 0; } void putchar(char val) { asm("movb %0, %%al\n" "movb $0x0E, %%a...

c program pointer

Hello , I am trying some programs in c face a problem with this program can any one tell me what is the problem with this and i also want to know that when in the above case if the pointer value is incremented then will it over write the previous value address as #include<stdio.h> int main() { int a=9,*x; float b=3.6,*y; c...

Setting the first two bytes of a block of memory as a pointer or NULL while still accessing the rest of the block

Suppose I have a block of memory as such: void *block = malloc(sizeof(void *) + size); How do I set a pointer to the beginning of the block while still being able to access the rest of the reserved space? For this reason, I do not want to simply assign 'block' to another pointer or NULL. ...

How to @synthesize a C-Style array of pointers?

I have a property defined in a class like so: @interface myClass UIImageView *drawImage[4]; ... @property (nonatomic, retain) UIImageView **drawImage; ... @synthesize drawImage; // This fails to compile I have found similar questions on StackOverflow and elsewhere, but none that really address this issue. What is the most Objective-C...

C++ arrays as parameters, EDIT: now includes variable scoping

Alright, I'm guessing this is an easy question, so I'll take the knocks, but I'm not finding what I need on google or SO. I'd like to create an array in one place, and populate it inside a different function. I define a function: void someFunction(double results[]) { for (int i = 0; i<100; ++i) { for (int n = 0; n<16; +...

Convert "this" to a reference-to-pointer

Just stumbled onto this problem. (title says it all) Let's say I have a struct struct Foo { void bar () { do_baz(this); } /* See edit below void do_baz(Foo*& pFoo) { pFoo->p_sub_foo = new Foo; // for example } */ Foo* p_sub_foo; } GCC tells me that temp.cpp: In member function ‘void Foo::ba...

the "new" operator in c++, pointer question

Dumb question, but whenever you call new, do you always have a pointer? SomeClass *person = new SomeClass(); And is that because you need a pointer to point to that new space of memory that was allocated for the SomeClass variable person? Thanks! ...