Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > How to get rid ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 20 Topic 9286 of 10094
Post > Topic >>

How to get rid of the new-initializer in a new-expression

by "Matthias Hofmann" <hofmann@[EMAIL PROTECTED] > Feb 15, 2008 at 02:50 PM

Hello everyone!

I have written a memory tracker using macros, and everything works fine
unless the new-expression contains a new-initializer. Please take a look
at
the following example:

template <class T> T* TrackNew( T* ptr ) { return ptr; }

#define NEW( T ) TrackNew<T>( new T )

struct X
{
     X() {}
     X( int ) {}
};

int main()
{
     // Works fine.
     X* p1 = NEW( X );

     // Fails to compile.
     X* p2 = NEW( X( 2 ) );

     return 0;
}

The second use of the NEW macro expands to:

X* p2 = TrackNew<X( 2 )>( new X( 2 ) );

Obviously, this should be:

X* p2 = TrackNew<X>( new X( 2 ) );

Can anyone please tell me a ****table way of getting rid of the
new-initializer in the new-expression? Like in the following pseudo code:

#define NEW( T ) TrackNew<REMOVE_NEW_INITIALIZER( T )>( new T )

-- 
Matthias Hofmann
Anvil-Soft, CEO
http://www.anvil-soft.com
- The Creators of Toilet Tycoon
http://www.anvil-soft.de
- Die Macher des Klomanagers



      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 20 Posts in Topic:
How to get rid of the new-initializer in a new-expression
"Matthias Hofmann&qu  2008-02-15 14:50:38 
Re: How to get rid of the new-initializer in a new-expression
cbarron3@[EMAIL PROTECTED  2008-02-16 05:38:51 
Re: How to get rid of the new-initializer in a new-expression
Thomas Maeder <maeder@  2008-02-16 05:52:44 
Re: How to get rid of the new-initializer in a new-expression
Bart van Ingen Schenau &l  2008-02-16 15:16:16 
Re: How to get rid of the new-initializer in a new-expression
"Alf P. Steinbach&qu  2008-02-17 10:35:46 
Re: How to get rid of the new-initializer in a new-expression
Alberto Ganesh Barbati &l  2008-02-17 21:21:44 
Re: How to get rid of the new-initializer in a new-expression
"Matthias Hofmann&qu  2008-02-18 18:09:57 
Re: How to get rid of the new-initializer in a new-expression
"Matthias Hofmann&qu  2008-02-18 18:09:44 
Re: How to get rid of the new-initializer in a new-expression
Carl Barron <cbarron41  2008-02-19 01:08:27 
Re: How to get rid of the new-initializer in a new-expression
"Matthias Hofmann&qu  2008-02-19 04:36:57 
Re: How to get rid of the new-initializer in a new-expression
"Matthias Hofmann&qu  2008-02-19 07:58:26 
Re: How to get rid of the new-initializer in a new-expression
Thomas Maeder <maeder@  2008-02-19 16:44:26 
Re: How to get rid of the new-initializer in a new-expression
"Matthias Hofmann&qu  2008-02-21 07:18:16 
Re: How to get rid of the new-initializer in a new-expression
Jeff Schwab <jeff@[EMA  2008-02-21 22:34:04 
Re: How to get rid of the new-initializer in a new-expression
Thomas Maeder <maeder@  2008-02-21 22:31:28 
Re: How to get rid of the new-initializer in a new-expression
"Matthias Hofmann&qu  2008-02-22 08:42:30 
Re: How to get rid of the new-initializer in a new-expression
Jeff Schwab <jeff@[EMA  2008-02-22 23:41:48 
Re: How to get rid of the new-initializer in a new-expression
"Matthias Hofmann&qu  2008-02-28 05:13:00 
Re: How to get rid of the new-initializer in a new-expression
Jeff Schwab <jeff@[EMA  2008-02-28 17:09:49 
Re: How to get rid of the new-initializer in a new-expression
Yongwei Wu <wuyongwei@  2008-03-08 11:53:34 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Oct 11 18:32:17 CDT 2008.