Search Results

Search found 3255 results on 131 pages for 'pointers'.

Page 16/131 | < Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >

  • compilation error: request member in something not a structure of union

    - by Fantastic Fourier
    Hi everybody, I'm having the above error request member rv in something not a structure of union. I've googled it and several answers told me it's when working with a pointer but tries to access it as a struct, where I should be using -> instead of . int foo(void * arg, struct message * msg) { struct fd_info * info = (struct something *) arg; int * socks[MAX_CONNECTION]; socks = &(info->_socks); // where int * _socks[MAX_CONNECTION] in struct info // do other things rv = sendto(socks[i], &msg, sizeof(&msg), NULL, &(csys->client_address), sizeof(csys->client_address)); ... } The problem is all of the arguments i have are pointers. i'm confused as to what is wrong. thanks to any comments/thoughts.

    Read the article

  • vector<vector<largeObject>> vs. vector<vector<largeObject>*> in c++

    - by Leif Andersen
    Obviously it will vary depending on the compiler you use, but I'm curious as to the performance issues when doing vector<vector<largeObject>> vs. vector<vector<largeObject>*>, especially in c++. In specific: let's say that you have the outer vector full, and you want to start inserting elements into first inner vector. How will that be stored in memory if the outer vector is just storing pointers, as apposed to storing the whole inner vector. Will the whole outer vector have to be moved to gain more space, or will the inner vector be moved (assuming that space wasn't pre-allocated), causing problems with the outer vector? Thank you

    Read the article

  • how to get the type of a deferred template parameter

    - by smerlin
    Is there a way to get the defered type of a class template parameter ? template <class TPtr> struct foo { typedef TPtr ptr_type; typedef ??? element_type; /* shall be the type of a deferred TPtr*/ }; so foo<const char*>::element_type results in const char, and foo<std::vector<int>::iterator_type>::element_type results in int. i am aware of that i can use the value_type typedef for c++ iterators (like std::vector<int>::iterator_type::value_type), but raw pointers havent got a value_type typedef, so i am out of luck there.

    Read the article

  • Add C pointer to NSMutableArray

    - by Georges Oates Larsen
    I am writing an Objective-C program that deals with low level image memory. I am using ANSI-C structs for my data storage -- Full blown objects seem overkill seeing as the data I am storing is 100% data, with no methods to operate on that data. Specifically, I am writing a customizable posterization algorithm which relies on an array of colors -- This is where things get tricky. I am storing my colors as structs of three floats, and an integer flag (related to the posterization algorithm specifically). Everyhting is going well, except for one thing... [actual question] I can't figure out how to add pointers to an NSMutableArray! I know how to add an object, but adding a pointer to a struct seems to be more difficult -- I do not want NSMutableArray dereferencing my pointer and treating the struct as some sort of strange object. I want NSMutableArray to add the pointer its self to its collection. How do I go about doing this? Thanks in advance, G

    Read the article

  • What is the safest way to pass strings around in C?

    - by chucknelson
    I have a program in C using Solaris with VERY ancient compatibility it seems. Many examples, even here on SO, don't work, as well as lots of code I've written on Mac OS X. So when using very strict C, what is the safest way to pass strings? I'm currently using char pointers all over the place, due to what I thought was simplicity. So I have functions that return char*, I'm passing char* to them, etc. I'm already seeing strange behavior, like a char* I passed having its value right when I enter a function, and then the value being mysteriously gone OR corrupted/overwritten after something simple like one printf() or an malloc to some other pointer. I was thinking maybe declaring a local char[] inside each function, using strcpy() immediately, and then eventually returning a pointer where char *returnval = strdup(localchar[]); This seems...sloppy. Can anyone point me in the right direction on a simple requirement?

    Read the article

  • Pointing to vectors

    - by Matt Munson
    #include <iostream> #include <vector> using namespace std; int main () { vector <int> qwerty; qwerty.push_back(5); vector <int>* p = &qwerty; cout << p[0]; //error: no match for 'operator<<' in 'std::cout << * p' } I'm generally unclear on how to use pointers with vectors, so I'm pretty mystified as to why this is not working. To my mind, this should print 5 to screen.

    Read the article

  • Remove from a std::set<shared_ptr<T>> by T*

    - by Autopulated
    I have a set of shared pointers: std::set<boost::shared_ptr<T>> set; And a pointer: T* p; I would like to efficiently remove the element of set equal to p, but I can't do this with any of the members of set, or any of the standard algorithms, since T* is a completely different type to boost::shared_ptr<T>. A few approaches I can think of are: somehow constructing a new shared_ptr from the pointer that won't take ownership of the pointed to memory (ideal solution, but I can't see how to do this) wrapping / re-implementing shared_ptr so that I can do the above just doing my own binary search over the set Help!

    Read the article

  • Pointer-based binary heap implementation

    - by Derek Chiang
    Is it even possible to implement a binary heap using pointers rather than an array? I have searched around the internet (including SO) and no answer can be found. The main problem here is that, how do you keep track of the last pointer? When you insert X into the heap, you place X at the last pointer and then bubble it up. Now, where does the last pointer point to? And also, what happens when you want to remove the root? You exchange the root with the last element, and then bubble the new root down. Now, how do you know what's the new "last element" that you need when you remove root again?

    Read the article

  • C Class Instance from Void Pointer using Ctypes

    - by g.d.d.c
    I've got a C DLL that exposes a handful of methods that return void pointers to a Class like so: void *GetLicense() { static AppLicenseImpl ipds_; return (void *) &ipds_; } In C++, after loading the DLL, I'd do this to work with it: typedef void *(* FPGetLicense)(); GetLicense_ = (FPGetLicense)GetAddress("GetLicense"); license_ = (AppLicense *) GetLicense_(); license_->GetApplicationStatus(); // Load data so that other calls don't fail I can't figure out how to parallel that in Python. This gets me the pointer: d = ctypes.cdll.LoadLibrary('license.dll') d.GetLicense.restype = ctypes.c_void_p p = d.GetLicense() # returns ptr loc, something like 8791433660848L But I obviously can't call p.GetApplicationStatus() in Python. Does anyone have a suggestion on how I'd instantiate that Class the rest of the way in Python so that I can call GetApplicationStatus()?

    Read the article

  • Void pointer values comparing C++

    - by user2962977
    My actual question is it really possible to compare values contained in two void pointers, when you actually know that these values are the same type? For example int. void compVoids(void *firstVal, void *secondVal){ if (firstVal < secondVal){ cout << "This will not make any sense as this will compare addresses, not values" << endl; } } Actually I need to compare two void pointer values, while outside the function it is known that the type is int. I do not want to use comparison of int inside the function. So this will not work for me as well: if (*(int*)firstVal > *(int*)secondVal) Any suggestions? Thank you very much for help!

    Read the article

  • Returning new base class when the parent class shared pointer is the return type

    - by Ben Dol
    Can you have a parent class shared pointer return type of a function and then return a new child class without it being a shared pointer? I'm not sure how shared pointers work in these situations, do they act like a regular pointer? Here is my example: BaseEventPtr Actions::getEvent(const std::string& nodeName) { if(asLowerCaseString(nodeName) == "action") return new ActionEvent(&m_interface); return nullptr; } ActionEvent is the subclass of BaseEvent in this situation. Cheers!

    Read the article

  • [C#] How to share a variable between two classes?

    - by Altefquatre
    Hello, How would you share the same object between two other objects? For instance, I'd like something in that flavor: class A { private string foo_; // It could be any other class/struct too (Vector3, Matrix...) public A (string shared) { this.foo_ = shared; } public void Bar() { this.foo_ = "changed"; } } ... // inside main string str = "test"; A a = new A(str); Console.WriteLine(str); // "test" a.Bar(); Console.WriteLine(str); // I get "test" instead of "changed"... :( I read there is some ref/out stuff, but I couldn't get what I'm asking here. I could only apply some changes in the methods scope where I was using ref/out arguments... I also read we could use pointers, but is there no other way to do it? Thanks Altefquatre

    Read the article

  • Store address dynamic array in c

    - by user280642
    I'm trying to save the address of a dynamic array index. struct sstor *dlist; struct node *q; q->item = &(dlist->item[(dlist->sz)-1]); // Problem? This is my node struct node { char **item; struct node *next; struct node *prev; }; This is my array struct sstor { int sz; int maxsz; char item[][1024]; }; I'm still new to pointers. The line below gives the error: assignment from incompatible pointer type q->item = &(dlist->item[(dlist->sz)-1]);

    Read the article

  • a nicer way to create structs in a loop

    - by sandra
    Hi guys, I haven't coded in C++ in ages. And recently, I'm trying to work on something involving structs. Like this typedef struct{ int x; int y; } Point; Then in a loop, I'm trying to create new structs and put pointers to them them in a list. Point* p; int i, j; while (condition){ // compute values for i and j with some function... p = new Point; p* = {i, j}; //initialize my struct. list.append(p); //append this pointer to my list. } Now, my question is it possible to simplify this? I mean, the pointer variable *p outside of the loop and calling p = new Point inside the loop. Isn't there a better/nicer syntax for this?

    Read the article

  • How to get function's name from function's pointer in C?

    - by Daniel Silveira
    How to get function's name from function's pointer in C? Edit: The real case is: I'm writing a linux kernel module and I'm calling kernel functions. Some of these functions are pointers and I want to inspect the code of that function in the kernel source. But I don't know which function it is pointing to. I thought it could be done because, when the system fails (kernel panic) it prints out in the screen the current callstack with function's names. But, I guess I was wrong... am I?

    Read the article

  • Syncronizing indices of function pointer table to table contents

    - by Thomas Matthews
    In the embedded system I'm working on, we are using a table of function pointers to support proprietary Dynamic Libraries. We have a header file that uses named constants (#define) for the function pointer indices. These values are used in calculating the location in the table of the function's address. Example: *(export_table.c)* // Assume each function in the table has an associated declaration typedef void (*Function_Ptr)(void); Function_Ptr Export_Function_Table[] = { 0, Print, Read, Write, Process, }; Here is the header file: *export_table.h* #define ID_PRINT_FUNCTION 1 #define ID_READ_FUNCTION 2 #define ID_WRITE_FUNCTION 3 #define ID_PROCESS_FUNCTION 4 I'm looking for a scheme to define the named constants in terms of their location in the array so that when the order of the functions changes, the constants will also change. (Also, I would like the compiler or preprocessor to calculate the indices to avoid human mistakes like typeo's.)

    Read the article

  • Dynamic creation of a pointer function in c++

    - by Liberalkid
    I was working on my advanced calculus homework today and we're doing some iteration methods along the lines of newton's method to find solutions to things like x^2=2. It got me thinking that I could write a function that would take two function pointers, one to the function itself and one to the derivative and automate the process. This wouldn't be too challenging, then I started thinking could I have the user input a function and parse that input (yes I can do that). But can I then dynamically create a pointer to a one-variable function in c++. For instance if x^2+x, can I make a function double function(double x){ return x*x+x;} during run-time. Is this remotely feasible, or is it along the lines of self-modifying code?

    Read the article

  • Custom deleters for std::shared_ptrs

    - by Kristian D'Amato
    Is it possible to use a custom deleter after creating a std::shared_ptr without using new? My problem is that object creation is handled by a factory class and its constructors & destructors are protected, which gives a compile error, and I don't want to use new because of its drawbacks. To elaborate: I prefer to create shared pointers like this, which doesn't let you set a custom deleter (I think): auto sp1 = make_shared<Song>(L"The Beatles", L"Im Happy Just to Dance With You"); Or I can create them like this, which does let met set a deleter through an argument: auto sp2(new Song, MyDeleterFunc); But the second one uses new, which AFAIK isn't as efficient as the top sort of allocation. Maybe this is clearer: is it possible to get the benefits of make_shared<> as well as a custom deleter? Would that mean having to write an allocator?

    Read the article

  • Jagged Array in C (3D)

    - by Daniel
    How could I do the following? double layer1[][3] = { {0.1,0.1,0.8}, {0.1,0.1,0.8}, {0.1,0.1,0.8}, {0.1,0.1,0.8} }; double layer2[][5] = { {0.1,0.1,0.1,0.1,0.8} }; double *upper[] = {layer1, layer2}; I read the following after trying different ideas; to no avail. jagged array in c I understand (I hope) that double **upper[] = {layer1, layer2}; Is similar to what I'd like, but would not work because the layers are not arrays of pointers. I am using C intentionally. I am trying to abstain from doing this (which works). double l10[] = {0.1,0.1,0.8}; //l11 etc double *l1[] = {l10,l11,l12,l13}; double l20[] = {0.1,0.1,0.1,0.1,0.8}; double *l2[] = {l20}; double **both[] = {l1, l2};

    Read the article

  • How does the below program work in c++?

    - by Srinivasa Varadan
    I have just created 2 pointers which has undefined behavior and try to invoke a class member function which has no object created ? I don't understand this? #include<iostream> using namespace std; class Animal { public: void talk() { cout<<"I am an animal"<<endl; } }; class Dog : public Animal { public: void talk() { cout<<"bark"<<endl; } }; int main() { Animal * a; Dog * d; d->talk(); a->talk(); }

    Read the article

  • Duplicate array but maintain pointer links

    - by St. John Johnson
    Suppose I have an array of nodes (objects). I need to create a duplicate of this array that I can modify without affecting the source array. But changing the nodes will affect the source nodes. Basically maintaining pointers to the objects instead of duplicating their values. // node(x, y) $array[0] = new node(15, 10); $array[1] = new node(30, -10); $array[2] = new node(-2, 49); // Some sort of copy system $array2 = $array; // Just to show modification to the array doesn't affect the source array array_pop($array2); if (count($array) == count($array2)) echo "Fail"; // Changing the node value should affect the source array $array2[0]->x = 30; if ($array2[0]->x == $array[0]->x) echo "Goal"; What would be the best way to do this?

    Read the article

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

    - by mystify
    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 to myBetterProperty results in accessing what's behind something. Assigning an value to myBetterProperty should result in assigning one to something, and vice versa. How to? Pointers set up in init? How would that look like? *self.myBetterProperty = &something; ? I'm not sure about that...

    Read the article

  • CString a = "Hello " + "World!"; Is it possible?

    - by Sanctus2099
    I'm making my own string class and I was wondering if there's any way to replace the compiler behaviour around " characters. As I said in the title I'd like to make it so that CString a = "Hello " + "World!"; would actually work and not give a compiler error telling that it can't add 2 pointers. My string class automatically converts to char* when needed and thus writing printf(a) would not break the code. I'm sure this is a rather weird question but if it's possible I'd really like to know how to do it. Thank you very much

    Read the article

  • C - How to manipulate typedef structure pointer?

    - by AbhishekJoshi
    typedef struct { int id; char* first; char* last; }* person; person* people; Hi. How can I use this above, all set globally, to fill people with different "person"s? I am having issues wrapping my head regarding the typedef struct pointer. I am aware pointers are like arrays, but I'm having issues getting this all together... I would like to keep the above code as is as well. Edit 1: char first should be char* first.

    Read the article

  • Call by Reference Function in C

    - by Chad
    Hello everyone, I would just like a push in the right direction here with my homework assignment. Here is the question: (1) Write a C function called input which returns void, this function prompts the user for input of two integers followed by a double precision value. This function reads these values from the keyboard and finds the product of the two integers entered. The function uses call by reference to communicate the values of the three values read and the product calculated back to the main program. The main program then prints the three values read and the product calculated. Provide test results for the input: 3 5 23.5. Do not use arrays or global variables in your program. And here is my code: #include <stdio.h> #include <stdlib.h> void input(int *day, int *month, double *k, double *pro); int main(void){ int i,j; double k, pro; input(&i, &j, &k, &pro); printf("%f\n", pro); return 0; } void input(int *i, int *j, double *k, double *pro){ int x,y; double z; double product; scanf("%d", &x); scanf("%d", &y); scanf("%f", &z); *pro += (x * y * z); } I can't figure out how to reference the variables with pointers really, it is just not working out for me. Any help would be great!

    Read the article

< Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >