pointers

Reference to pointers and C++ polymorphism

Hi, does anyone know why this gives a compiler error ? I tried VS 2005 and Codewarrior: class Parent { protected: int m_Var; public: Parent() : m_Var(0) {} virtual ~Parent() {} void PubFunc(); }; class Child : public Parent { protected: bool m_Bool; public: Child() : m_Bool(false) {} ...

Initializing pointers in C++

Can assign a pointer to a value on declaration? Something like this: int * p = &(1000) ...

Why does NSError need double indirection? (pointer to a pointer)

This concept seems to trouble me. Why does an NSError object need its pointer passed to a method that is modifying the object? For instance, wouldn't just passing a reference to the error do the same thing? NSError *anError; [myObjc doStuff:withAnotherObj error:error]; and then in doStuff: - (void)doStuff:(id)withAnotherObjc error:(...

Does C++ do value initialization of a POD typedef?

Does C++ do value initialization on simple POD typedefs? Assuming typedef T* Ptr; does Ptr() do value-initialization and guarantee to equal (T*)0? e.g. Ptr p = Ptr(); return Ptr(); ...

Using strsep() with dynamic array of strings in C

I have the following code: #include <string.h> int main(void) { char *buffer = NULL, **words = NULL, *aPtr = NULL, *sPtr; int count = 0; buffer = strdup("The quick brown fox jumps over the lazy dog"); sPtr = buffer; do { aPtr = strsep(&sPtr, " "); words[count++] = ... // missing code } while(aPtr); ...

Is there a smart pointer that is automatically nulled when its target is destroyed in C++

I've found QPointer. Are there any others? ...

Are there are any platforms where pointers to different types have different sizes?

The C standard allows pointers to different types to have different sizes, e.g. sizeof(char*) != sizeof(int*) is permitted. It does, however, require that if a pointer is converted to a void* and then back to its original type, it must compare as equal to its original value. Therefore, it follows logically that sizeof(void*) >= sizeof(...

Objective-C instance variable pointers

Hello hello, I'm new to objective C and I just wanted to get a general clarification on when to use a pointer and when not to, when declaring instance variables. The example I can think of is UIView vs. a BOOL. UIView I would make a pointer, BOOL I would not (because the compiler yelled at me). Any general guidance would be awesome. ...

C++ Array Shuffle

I'm fairly new to C++ and don't quite understand function parameters with pointers and references. I have an array of Cards that I want to shuffle using the Fisher-Yates shuffle. The deck is declared as Card *deck[deckSize]; where deckSize has been declared as 24. The array is then initialized. I then call the shuffle function: v...

Copying an integer to a Buffer memcpy C++

Basically I would like to store the address of a pointer in a buffer. Don't ask me why char * buff = "myBuff"; char * myData = (char*)malloc(sizeof(char*)); int addressOfArgTwo = (unsigned int)buff; memcpy(myData, &addressOfArgTwo, sizeof(char*)); cout << "Int Val: " << addressOfArgTwo << endl; cout << "Address in buffer:" << (unsigned...

Deleting a heap then dereferencing a pointer to that memory

This is code from an exercise: #include <iostream> using namespace std; int main() { int n = 13; int* ip = new int(n + 3); int* ip2 = ip; cout << *ip << endl; delete ip; cout << *ip2 << endl; cout << ip << tab << ip2 << endl; } When the space allocated to the int on the heap is deleted, I thought that dere...

Exists any alternative more beautiful at this loop?

$i=0; while ($row=mysql_fetch_assoc()) { if ($i==0) echo "First" $i++; } Access directly to mysqli pointer? a php class like's Iterator? Thanks. ...

What is the default constructor for C++ pointer?

I have code like this: class MapIndex { private: typedef std::map<std::string, MapIndex*> Container; Container mapM; public: void add(std::list<std::tring>& values) { if (values.empty()) // sanity check return; std::string s(*(values.begin())); values.erase(values.begin()); i...

How to pass pointer to an array in Python for a wrapped C++ function

I am new to C++/Python mixed language programming and do not have much idea about Python/C API. I just started using Boost.Python to wrap a C++ library for Python. I am stuck at wrapping a function that takes pointer to an array as an argument. Following (2nd ctor) is its prototype in C++. class AAF{ AAF(AAF_TYPE t); AAF(double v0, ...

c# p/invoke difficulties marshalling pointers

I am attempting to call into a native .dll from c# using p/invoke. I'm able to make the call (no crash, the function returns a value), but the return code indicates "A pointer parameter does not point to accessible memory." I've resorted to trial and error in order to solve this, but I haven't made any progress so far. Here's the sig...

Function pointer problem

I am trying to use a function pointer, but the 3 lines below just do not seem to want to cooperate... I'm getting error code C3867. Can you see what I'm doing wrong? In .h file void MyFunc(int, FILEINFO*(*)(FILEINFO*), FILEINFO*, int); The definition in the .cpp file void MyFunc(int number, FILEINFO*(*GetFiles)(FILEINFO*), FILEINF...

assigning character to char pointer

With c-style strings, how do you assign a char to a memory address that a character pointer points to? For example, in the example below, I want to change num to "123456", so I tried to set p to the digit where '0' is located and I try to overwrite it with '4'. Thanks. #include <stdio.h> #include <stdlib.h> int main() { char* num ...

How to get the address of a value, pointed to by a pointer...

I have a pointer to an int. int index = 3; int * index_ptr = &index; index_ptr is a member variable of a class IndexHandler. class A has a std::vector of IndexHandlers, Avector. class B has a std::vector of pointers to IndexHandlers, Bvector, which I set to point to the items in class A's vector, thusly: Bvector.push_back(Avector[i]...

constants and pointers in C

I wanted to change value of a constant by using pointers. Consider the following code int main() { const int const_val = 10; int *ptr_to_const = &const_val; printf("Value of constant is %d",const_val); *ptr_to_const = 20; printf("Value of constant is %d",const_val); return 0; } As expected the value of consta...

What's the best portable way to represent pointer as string in C++?

I need to represent pointers as strings to the user. Sometimes the values might be saved to a file and transferred to a computer with different architecture (32 vs 64 bit is the main issue currently) and loaded from text file to be compared - I'm only going to compare loaded values with each other, but I'd still prefer to compare numbers...