Search Results

Search found 3592 results on 144 pages for 'pointer'.

Page 2/144 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Base class pointer vs inherited class pointer?

    - by Goose Bumper
    Suppose I have a class Dog that inherits from a class Animal. What is the difference between these two lines of code? Animal *a = new Dog(); Dog *d = new Dog(); In one, the pointer is for the base class, and in the other, the pointer is for the derived class. But when would this distinction become important? For polymorphism, either one would work exactly the same, right?

    Read the article

  • pointer-to-pointer of derived class in multiple inheritance

    - by Abdul jalil
    i have 3 classes A,B and C. C is derived from A and B. i get pointer to pointer of class C and cast to A** , and B ** , the variable that hold the the B** has the address of A** in my example B ** BdoublePtr hold the address of A** .i am using the following code #include "conio.h" #include "stdio.h" #include "string.h" class A{ public: A() { strA=new char[30]; strcpy(strA,"class A"); } char *strA; }; class B { public: B() { strB=new char[30]; strcpy(strB,"class B"); } char *strB; }; class C :public A, public B { public: C() { strC=new char[30]; strcpy(strC,"class C"); } char *strC; }; int main(void) { C* ptrC=new C(); A * Aptr=(A*)ptrC; printf("\n class A value : %s",Aptr-strA); B * Bptr=(B*)ptrC; printf("\n class B value :%s",Bptr-strB); printf("\n\nnow with double pointer "); A ** AdoublePtr=(A **)&ptrC; Aptr=AdoublePtr; printf("\n class A value : %s",Aptr-strA); B * BdoublePtr=(B **)&ptrC; Bptr=*BdoublePtr; printf("\n class B value : %s",Bptr-strB); getch(); return 0; }

    Read the article

  • C++, function pointer to the template function pointer

    - by Ian
    I am having a pointer to the common static method class MyClass { private: static double ( *pfunction ) ( const Object *, const Object *); ... }; pointing to the static method class SomeClass { public: static double getA ( const Object *o1, const Object *o2); ... }; Initialization: double ( *MyClass::pfunction ) ( const Object *o1, const Object *o2 ) = &SomeClass::getA; I would like to convert this pointer to the static template function pointer: template <class T> static T ( *pfunction ) ( const Object <T> *, const Object <T> *); //Compile error where: class SomeClass { public: template <class T> static double getA ( const Object <T> *o1, const Object <T> *o2); ... }; But there is some error... Thanks for your help...

    Read the article

  • pointer to a pointer in a linked list

    - by user1596497
    I'm trying to set a linked list head through pointer to a pointer. I can see inside the function that the address of the head pointer is changing but as i return to the main progran it becomes NULL again. can someone tell me what I'm doing wrong ?? #include <stdio.h> #include <stdlib.h> typedef void(*fun_t)(int); typedef struct timer_t { int time; fun_t func; struct timer_t *next; }TIMER_T; void add_timer(int sec, fun_t func, TIMER_T *head); void run_timers(TIMER_T **head); void timer_func(int); int main(void) { TIMER_T *head = NULL; int time = 1; fun_t func = timer_func; while (time < 1000) { printf("\nCalling add_timer(time=%d, func=0x%x, head=0x%x)\n", time, func, &head); add_timer(time, func, head); time *= 2; } run_timers(&head); return 0; } void add_timer(int sec, fun_t func, TIMER_T *head) { TIMER_T ** ppScan=&head; TIMER_T *new_timer = NULL; new_timer = (TIMER_T*)malloc(sizeof(TIMER_T)); new_timer->time = sec; new_timer->func = func; new_timer->next = NULL; while((*ppScan != NULL) && (((**ppScan).time)<sec)) ppScan = &(*ppScan)->next; new_timer->next = *ppScan; *ppScan = new_timer; }

    Read the article

  • Pointer initialization

    - by SoulBeaver
    Sorry if this question has been asked before. On my search through SO I didn't find one that asked what I wanted to know. Basically, when I have this: typedef struct node { int data; node *node; } *head; and do node *newItem = new node; I am under the impression that I am declaring and reserving space, but not defining, a pointer to struct node, is that correct? So when I do newItem->data = 100 and newItem->next = 0 I get confused. newItem = 0would declare what exactly? Both data and next? The object as a whole? I'm especially confused when I use typedef. Which part is the macro? I assume node because that's how I call it, but why do I need it? Finally, what happens when I do: node *temp; temp = new node; temp = head->next; head->next = newItem; newItem->next = temp; I mean, head-next is a pointer pointing to object newItem, so I assume not to newItem.data or next themselves. So how can I use an uninitialized pointer that I described above safely like here? is head now not pointing to an uninitialized pointer?

    Read the article

  • c program pointer

    - by sandy101
    Hello , I am trying some programs in c face a problem with this program #include<stdio.h> int main() { int a=9,*x; float b=3.6,*y; char c='a',*z; printf("the value is %d\n",a); printf("the value is %f\n",b); printf("the value is %c\n",c); x=&a; y=&b; z=&c; printf("%u\n",a); printf("%u\n",b); printf("%u\n",c); x++; y++; z++; printf("%u\n",a); printf("%u\n",b); printf("%u\n",c); return 0; } 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 suppose that the value we got in the above program (without the increment in the pointer value )is 65524 65520 65519 and after the increment the value of the pointer is 65526(as 2 increment for the int ) 65524(as 4 increment for the float ) 65520(as 1 increment for the char variable ) then if in that case will the new pointer address overwrite the content of the previous address and what value be contained at the new address ......plz help

    Read the article

  • commands&creating pointer [closed]

    - by gcc
    input 23 3 4 4 42 n 23 0 9 9 n n n 3 9 9 x //according to input,i should create int pointer arrays. pointer arrays // starting from 1 (that is initial arrays is arrays[1].when program sees n ,it // must be jumb to arrays 2 // the first int input 23 is num_arrays which used in malloc(sizeof(int)*num_arrays expected output: elements of arrays[1] 3 4 5 42 elements of arrays[2] 23 0 9 9 elements of arrays[5] 3 9 9 another input 12 2 3 4 n n 2 3 4 n 12 3 x expected output elements of arrays[1] 2 3 4 elements of arrays[3] 2 3 4 elements of arrays[4] 12 3 specification: x is stopper n is comman to create new pointer array i am new in this site anyone help me how can i write

    Read the article

  • n & x commands&creating pointer&with using malloc [closed]

    - by gcc
    input 23 3 4 4 42 n 23 0 9 9 n n n 3 9 9 x //according to input,i should create int pointer arrays. pointer arrays // starting from 1 (that is initial arrays is arrays[1].when program sees n ,it // must be jumb to arrays 2 // the first int input 23 is num_arrays which used in malloc(sizeof(int)*num_arrays expected output arrays[1] 3 4 5 42 arrays[2] 23 0 9 9 arrays[5] 3 9 9 another input 12 2 3 4 n n 2 3 4 n 12 3 x expected output arrays[1] 2 3 4 arrays[3] 2 3 4 arrays[4] 12 3 x is stopper n is comman to create new pointer array i am new in this site anyone help me how can i write

    Read the article

  • Question on Pointer Arithmetic

    - by pws5068
    Heyy Everybody! I am trying to create a memory management system, so that a user can call myMalloc, a method I created. I have a linked list keeping track of my free memory. My problem is when I am attempting to find the end of a free bit in my linked list. I am attempting to add the size of the memory free in that section (which is in the linked list) to the pointer to the front of the free space, like this. void *tailEnd = previousPlace->head_ptr + ((previousPlace->size+1)*(sizeof(int)); I was hoping that this would give me a pointer to the end of that segment. However, I keep getting the warning: "pointer of type 'void*' used in arithmetic" Is there a better way of doing this? Thanks!

    Read the article

  • "Initializing" the pointer in the separate function in C

    - by pechenie
    I need to do a simple thing, which I used to do many times in Java, but I'm stuck in C (pure C, not C++). The situation looks like this: int *a; void initArray( int *arr ) { arr = malloc( sizeof( int ) * SIZE ); } int main() { initArray( a ); // a is NULL here! what to do?! return 0; } I have some "initializing" function, which SHOULD assign a given pointer to some allocated data (doesn't matter). How should I give a pointer to a function in order to this pointer will be modified, and then can be used further in the code (after that function call returns)? Thanx for help.

    Read the article

  • Passing NSArray Pointer Rather Than A Pointer To a Specific Type

    - by mattmccomb
    I've just written a piece of code to display a UIActionSheet within my app. Whilst looking at the code to initialise my UIActionSheet something struck me as a little strange. The initialisation function has the following signature... initWithTitle:(NSString *)title delegate:(id UIActionSheetDelegate)delegate cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle otherButtonTitles:(NSString *)otherButtonTitles As you can see the otherButtonTitles parameter is a pointer to a String. In my code I set it as follows... otherButtonTitles: @"Title", @"Date", nil Although this compiles fine I don't really understand how it works. My reading of the statement is that I have created an inline array containing two elements (Title and Date). How come this then compiles? I'm passing a NSArray* in place of a NSString*. I know from a little of understanding of C++ that an array is really a pointer to the first element. So is this inline array that I'm creating a C array as opposed to a NSArray? What I'm hoping to achieve is to be able to pass a static NSArray* used elsewhere in my class to the otherButtonTitles parameter. But passing the NSArray* object directly doesn't work.

    Read the article

  • Normal pointer vs Auto pointer (std::auto_ptr)

    - by AKN
    Code snippet (normal pointer) int *pi = new int; int i = 90; pi = &i; int k = *pi + 10; cout<<k<<endl; delete pi; [Output: 100] Code snippet (auto pointer) Case 1: std::auto_ptr<int> pi(new int); int i = 90; pi = &i; int k = *pi + 10; //Throws unhandled exception error at this point while debugging. cout<<k<<endl; //delete pi; (It deletes by itself when goes out of scope. So explicit 'delete' call not required) Case 2: std::auto_ptr<int> pi(new int); int i = 90; *pi = 90; int k = *pi + 10; cout<<k<<endl; [Output: 100] Can someone please tell why it failed to work for case 1?

    Read the article

  • segmentation fault when using pointer to pointer

    - by user3697730
    I had been trying to use a pointer to pointer in a function,but is seems that I am not doing the memory allocation correctly... My code is: #include<stdio.h> #include<math.h> #include<ctype.h> #include<stdlib.h> #include<string.h> struct list{ int data; struct list *next; }; void abc (struct list **l,struct list **l2) { *l2=NULL; l2=(struct list**)malloc( sizeof(struct list*)); (*l)->data=12; printf("%d",(*l)->data); (*l2)->next=*l2; } int main() { struct list *l,*l2; abc(&l,&l2); system("pause"); return(0); } This code compiles,but I cannot run thw program..I get a segmentation fault..What should I do?Any help would be appreciated!

    Read the article

  • Handles and pointer to object

    - by Tony
    I have a python Interpreter written in C++, the PyRun_String function from the Python API is said to return a handle, however in my code I have it assigned to pointer to a PyObject? PyObject* presult = PyRun_String(code, parse_mode, dict, dict); Is this actually correct? Can you implicitly cast this handle to this object pointer? Should it not be a HANDLE instead?

    Read the article

  • pointer is always byte aligned

    - by kumar
    Hi, I read something like pointer must be byte-aligned. My understanding in a typical 32bit architecture... all pointers are byte aligned...No ? Please confirm. can there be a pointer which is not byte-aligned ?

    Read the article

  • C++ pointer to objects

    - by Tony
    In C++ do you always have initialize a pointer to an object with the new keyword? Or can you just have this too: MyClass *myclass; myclass->DoSomething(); I thought this was a pointer allocated on the stack instead of the heap, but since objects are normally heap allocated, I think my theory is probably faulty?? Please advice.

    Read the article

  • The best way to have a pointer to several methods - critique requested

    - by user827992
    I'm starting with a short introduction of what i know from the C language: a pointer is a type that stores an adress or a NULL the * operator reads the left value of the variable on its right and use this value as address and reads the value of the variable at that address the & operator generate a pointer to the variable on its right so i was thinking that in C++ the pointers can work this way too, but i was wrong, to generate a pointer to a static method i have to do this: #include <iostream> class Foo{ public: static void dummy(void){ std::cout << "I'm dummy" << std::endl; }; }; int main(){ void (*p)(); p = Foo::dummy; // step 1 p(); p = &(Foo::dummy); // step 2 p(); p = Foo; // step 3 p->dummy(); return(0); } now i have several questions: why step 1 works why step 2 works too, looks like a "pointer to pointer" for p to me, very different from step 1 why step 3 is the only one that doesn't work and is the only one that makes some sort of sense to me, honestly how can i write an array of pointers or a pointer to pointers structure to store methods ( static or non-static from real objects ) what is the best syntax and coding style for generating a pointer to a method?

    Read the article

  • pointer in c and the c program

    - by sandy101
    Hello, I am studying the pointer and i come to this program .... #include <stdio.h> void swap(int *,int *); int main() { int a=10; int b=20; swap(&a,&b); printf("the value is %d and %d",a,b); return 0; } void swap(int *a,int*b) { int t; t=*a; *a=*b; *b=t; printf("%d and%d\n",*a,*b); } can any one tell me why this main function return the value reversed . The thing i understood till now is that the function call in c does not affect the main function and it's values . I also want to know how much the space a pointer variable occupied like integer have occupied the 2 bytes and the various application use and advantages of the pointer .... plz.... anyone help

    Read the article

  • Pointer to auto_ptr instead of a classical double pointer

    - by Pin
    Hello. I'm quite new to smart pointers and was trying to refactor some existing code to use auto_ptr. The question I have is about double pointers and their auto_ptr equivalent, if that makes sense. I have a function that accepts a double pointer as its parameter and the function allocates resources for it: void foo ( Image** img ) { ... *img = new Image(); ...} This function is then used like this: Image* img = NULL; foo ( &img ); ... delete img; I want to use auto_ptr to avoid having to call delete explicitly. Is the following correct? void foo ( auto_ptr<Image>* img ); and then auto_ptr<Image> img = NULL; foo ( &img ); Thanks.

    Read the article

  • Pointer to struct, containing pointer to an object, for which I want to call a function

    - by user1795609
    So I've created an ADT which is a singly linked list made up of nodes. These Nodes each have a pointer to an object in them called data. Class Structure { struct Node { Object *data; Node *next; }; }; Node *head; I am trying to call a function in the object, like this: head = new Node; head -> data = new Object(); head -> next = NULL; cout << head -> data.print(); I keep getting the following error at compile. error: request for member 'print' in 'head-Structure::Node::data', which is of non-class type 'Object'*

    Read the article

  • Call a void* as a function without declaring a function pointer

    - by ToxIk
    I've searched but couldn't find any results (my terminology may be off) so forgive me if this has been asked before. I was wondering if there is an easy way to call a void* as a function in C without first declaring a function pointer and then assigning the function pointer the address; ie. assuming the function to be called is type void(void) void *ptr; ptr = <some address>; ((void*())ptr)(); /* call ptr as function here */ with the above code, I get error C2066: cast to function type is illegal in VC2008 If this is possible, how would the syntax differ for functions with return types and multiple parameters?

    Read the article

  • pointer to const member function typedef

    - by oldcig
    I know it's possible to separate to create a pointer to member function like this struct K { void func() {} }; typedef void FuncType(); typedef FuncType K::* MemFuncType; MemFuncType pF = &K::func; Is there similar way to construct a pointer to a const function? I've tried adding const in various places with no success. I've played around with gcc some and if you do template deduction on something like template <typename Sig, typename Klass> void deduce(Sig Klass::*); It will show Sig with as a function signature with const just tacked on the end. If to do this in code it will complain that you can't have qualifiers on a function type. Seems like it should be possible somehow because the deduction works.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >