Sunday, July 6th 2008, 3:08pm UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, April 23rd 2008, 12:39pm

pointer

hi,

the function f(Mystruct* p) { p = new Mystruct }

is called f(ptr1) with ptr1 declared as Mystruct* ptr1.

but ptr1 is 0 whereas p has correct value.

what's wrong
thanks in advance
  • Go to the top of the page

stinos

Intermediate

2

Wednesday, April 23rd 2008, 12:56pm

passing a ointer results in a copy being pushed on the stack.
you don't want the copy, so pass the argument by reference:

Source code

1
2
3
4
5
template< class T >
void my_new( T*& p ){ p = new T(); }

template< class T >
void my_delete( T*& p ){ delete p; p = 0; }
madinsjamania
  • Go to the top of the page

3

Wednesday, April 23rd 2008, 1:46pm

thanx
  • Go to the top of the page

Rate this thread