pointers

How to map an property of ClassA to one of SuperclassA?

I have a class named SuperclassA, and an class named ClassA. ClassA inherits from SuperclassA. SuperclassA has got an property called something, so a very generic not-much-saying name. In ClassA, I want to have an property which maps to that something of SuperclassA. How could I do that? I want to make absolutely sure that any access t...

What does deleting a pointer mean?

Is deleting a pointer same as freeing a pointer (that deallocates the memory)? ...

Problem with memset after an instance of a user defined class is created and a file is opened

I'm having a weird problem with memset, that was something to do with a class I'm creating before it and a file I'm opening in the constructor. The class I'm working with normally reads in an array and transforms it into another array, but that's not important. The class I'm working with is: #include <vector> #include <algorithm> using ...

Python: Create a duplicate of an array

I have an double array alist[1][1]=-1 alist2=[] for x in xrange(10): alist2.append(alist[x]) alist2[1][1]=15 print alist[1][1] and I get 15. Clearly I'm passing a pointer rather than an actual variable... Is there an easy way to make a seperate double array (no shared pointers) without having to do a double for loop? Thanks, Da...

Asterisk sometimes on variable type, sometimes on variable name. Why?

In Objective-C, I've seen, for example: UIPickerView *tweetPicker and UIPickerView* tweetPicker What does the asterisk mean (I know, the first part is a dupe...) and why does it go on different parts of the deceleration in different contexts? ...

[C] Texture management / pointer question

I'm working on a texture management and animation solution for a small side project of mine. Although the project uses Allegro for rendering and input, my question mostly revolves around C and memory management. I wanted to post it here to get thoughts and insight into the approach, as I'm terrible when it comes to pointers. Essentiall...

Are pointers primitive types in C++?

I was wondering about the last constructor for std::string mentioned here. It says: template<class InputIterator> string (InputIterator begin, InputIterator end); If InputIterator is an integral type, behaves as the sixth constructor version (the one right above this) by typecasting begin and end to call it: string(static_cast<size_t...

generic programming in C with void pointer.

Hi everyone, even though it is possible to write generic code in C using void pointer(generic pointer), I find that it is quite difficult to debug the code since void pointer can take any pointer type without warning from compiler. (e.g function foo() take void pointer which is supposed to be pointer to struct, but compiler won't compla...

Getting Segmentation Fault in C++, but why?

I am getting segmentation fault in this code but i cant figure out why. I know a segmentation fault happens when a pointer is NULL, or when it points to a random memory address. q = p; while(q -> link != NULL){ q = q -> link; } t = new data; t -> city = cityName; t -> latitude = lat;...

Array length with pointers

How in C++ get array length with pointers only ? I know that tab name is pointer to first element, but what next ? ...

Operator precedence and struct definition in C

struct struct0 { int a; }; struct struct1 { struct struct0 structure0; int b; } rho; &rho->structure0; /* Reference 1 */ (struct struct0 *)rho; /* Reference 2 */ (struct struct0)rho; /* Reference 3 */ From reference 1, does the compiler take the address of rho, and then access structure0, or vice-versa? What does the line at ...

Can anybody explain how its printing output as "ink"

Hi I am new to pointers in C. I know the basic concepts. In the below code, why is it printing the "ink" as its output? #include<stdio.h> main() { static char *s[]={"black","white","pink","violet"}; char **ptr[]={s+3,s+2,s+1,s},***p; p=ptr; ++p; printf("%s",**p+1); } Thanks ...

Copying pointers in C++

Hello, I have a class A containing two pointers to objects of another class B. I want to initialize one pointer or the other depending on which one is passed to init(), which also takes other parameters. My situation is thus the following: class A { public: A(); init(int parameter, int otherParameter, B* toBeInitialized); prot...

How to check if a pointer is null in C++ Visual 2010

I am having problems here if I want to check if eerste points to nothing I get Blockquote Unhandled exception at 0x003921c6 in Bank.exe: 0xC0000005: Access violation reading location 0xccccccd0. and I am kinda wondering why he justs skips the if statement or doens't stop when the object eerste points to nothing Bank::Ban...

C++ - Difference between (*). and -> ?

Is there any difference in performance - or otherwise - between: ptr->a(); and (*ptr).a(); ? ...

Difference between char *foo vs (char *)foo in Objective-C

What is the difference between char *foo and (char *) foo in Objective-C? Here is an example for both scenarios: 1. @interface Worker: NSObject { char *foo; } 2. - initWithName:(char *)foo ...

How to read some bytes from BYTE*

I have BYTE pointer. For example the length of this BYTE array is 10. How can I read 4 bytes from 3 position BYTE array? Now I doing it so BYTE *source = "1234567890\0"; BYTE* tmp = new BYTE[4+1](); for(int i=0; i<4; i++) { tmp[i] = source[i+3]; } ...

SWIG: C++ to C#, pointer to pointer marshalling.

I have some legacy code I want to port to C#. I cannot modify the C++ code, I just have to make do with what I'm given. So, the situation. I'm using SwIG, and I came across this function: void MarshalMe(int iNum, FooClass** ioFooClassArray); If I ran SWIG over this, it wouldn't know what to do with the array, so it will create a SWIG...

Convert Pen to IntPtr

Is there a simple way to convert a System.Drawing.Pen into its unmanaged counterpart? Like, if you had a Pen like this: Pen p = new Pen(Color.Blue, 1f); IntPtr ptr = p.ToPtr(); I know this code doesn't work, but is there a way to do it similarly? ...

C++ return double pointer from function.... what's wrong?

I can't seem to figure out what's wrong with my function.... I need to ask the user for a price and then return it as a double pointer, but I get tons and tons of errors: double* getPrice() { double* price; cout << "Enter Price of CD: " << endl; cin >> &price; return price; } ...