FAQ Database Discussion Community


When I add up in my pointer address it points to my array? Why? Reference and Dereference confusion C++

c++,pointers,dereference,pointer-arithmetic,addressof
In this example, I have an array of four elements. I have declared a pointer to integer which contains the address of array. Then i have displayed the address of 0th index in 3 different ways. Similarly, the address of 1st index is displayed in 3 different ways. When I...

invalid type argument of '->' (have 'int')

c,pointers,dereference,operator-precedence,invalid-argument
I get the error reported below while I am compiling my code. Could you please correct me where I mistaken? invalid type argument of -> (have int) My code is as follows: #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> typedef struct bundles { char str[12]; struct bundles *right; }bundle;...

Understanding the Debug implementation for Vec

reference,rust,dereference
Trying to implement the Debug trait for a custom type I stumbled upon the implementation for Vec<T>. I have difficulties understanding how it works. The implementation goes like this: impl<T: fmt::Debug> fmt::Debug for Vec<T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Debug::fmt(&**self, f) } } I understand it...

What are Rust's exact auto-dereferencing rules?

pointers,reference,rust,dereference,formal-semantics
I'm learning/experimenting with Rust, and in all the elegance that I find in this language, there is one peculiarity that baffles me and seems totally out of place. Rust automatically dereferences pointers when making method calls. I made some tests to determine the exact behaviour: struct X { val: i32...

What does ** mean in C?

c,pointers,memory,reference,dereference
I have a sample C program I am trying to understand. Below is a function excerpt from the source code: double** Make2DDoubleArray(int arraySizeX, int arraySizeY) { double** theArray; theArray = (double**) malloc(arraySizeX*sizeof(double*)); int i = 0; for (i = 0; i < arraySizeX; i++) theArray[i] = (double*) malloc(arraySizeY*sizeof(double)); return theArray;...

C++ pointer vs dereferenced object

c++,qt,pointers,dereference
I have the following C++/Qt code: QTreeWidgetItem *itemPointer = this->widget->topLevelItem(0); QTreeWidgetItem item = *itemPointer; QTreeWidgetItem *itemPointer2 = &item; qDebug() << itemPointer->childCount(); // 2 (answer I'm looking for) qDebug() << (*itemPointer).childCount(); // 2 qDebug() << item.childCount(); // 0 qDebug() << itemPointer2->childCount(); // 0 qDebug() << itemPointer; // 0xeb6f70 qDebug() << itemPointer2;...

Why isn't the highest element not returning?

c,pointers,reference,dereference
I just learned about pointers and having trouble with this program. My int function is returning the first element of the array and not returning the highest element. I think I'm calling the wrong declaration to get the right element in the main, but I'm not sure that is true....

Implementing a list iterator and operators: — ++ *

c++,list,iterator,operators,dereference
Following on from this question: std::list implementation & pointer arithemetic. I want to implement a list iterator that is interchangeable with other common containers types and their respective iterators, so I want to use operators such as: --, ++, * and be able to declare iterators as normal, so: list::iterator...

base operand of ‘->’ has non-pointer type error

c++,pointers,dereference
I got the error " src/Graphics.cpp:29:32: erreur: base operand of ‘->’ has non-pointer type ‘std::vector’ " on the following code : Constructor : Graphics::Graphics() { this->app = new sf::RenderWindow(sf::VideoMode(800, 800, 32), "La Zapette !", sf::Style::Close | sf::Style::Titlebar); sf::Image img; img.LoadFromFile("./res/grass.jpg"); for (int i = 0; i != 16; i++) {...

dereferencing pointer to incomplete type (radix tree)

c,struct,dereference,radix-tree
I'm having major trouble with my struct definition. I have tried a couple different ways of defining them but can't seem to get rid of the error. I probably also have a wealth of other problems with the code but I can't actually fix those without finding them by running...

Tcl dereferencing: How to dereference a variable inside a string

tcl,dereference
I have following situation: % set a 20 20 % set in_word "Value of a is \$a" Value of a is $a Now, I would like to print (or set this string to another variable), Value of a is 20 by operating on the variable in_word. The similar (possibly the...

Skip Unused Virtual Function

c++,plugins,interface,null,dereference
I have main executable and two functions that are dereferenced to DLL. class CPluginInterface { public: virtual void A(void) = 0; virtual void B(void) = 0; }; I created DLL like this //Main.h #include "Function.h" class CForward : public CPluginInterface { public: //void A(void); void B(void); }; //Main.cpp #include "Main.h"...

Cast map structure to void pointer and dereference

c++,dictionary,casting,void-pointers,dereference
I have been trying to cast a map structure to a void pointer and cast it vice versa. void addToMap(void *data){ // add some elements to the map } map<string, vector<myStruct> > myMap; addToMap(&myMap); I am trying to send myMap to addToMap function as an argument and add some elements...

What's the difference between function with dereference and without dereference

c++,pointers,c++11,dereference
What's the difference between f1, (*f1), f2, (*f2) ? and what's the difference between (function) and (&function) ? #include <iostream> using namespace std; void function (char *s) { cout << s << endl; } int main () { void (*f1) (char*) = &function; void (*f2) (char*) = function; f1 ("f1...

Using Increment operator with de-referencing in C

c,pointers,compilation,compiler-errors,dereference
To my function i get a void pointer, I would like to point to the next location considering the incoming pointer is of char type. int doSomething( void * somePtr ) { ((char*)somePtr)++; // Gives Compilation error } I get the following compilation error: Error[Pe137]: expression must be a modifiable...

What is the difference between * and & in function parameters?

c,pointers,parameters,reference,dereference
I have seen something in this form: void function( A_struct &var ) { var.field0 = 0; // ... } Since there is & before var, I thought that var is a pointer. But in the body, instead of writing var->field0, var.field0 is written. So, my questions are: Isn't var a...

Can't access object variables passed in a std callback

c++,forward-declaration,dereference
I have a callback function (ouside my class) which i'm passing a BassMusicPlayer class object as parameter. If do a breakpoint inside it, i can see all the variables and methods in 'self'. If i try to read/print those values, it won't compile and will give error C2027: use of...