Thread: templates and preprocessor

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    73

    templates and preprocessor

    I have a definition...

    Code:
    #define MTrAllocatedObject(Type) MTrAllocatedObjectType<Type>
    ...and when I do this...

    Code:
    MTrAllocatedObject( MTrAllocatedObject( double ) ) MyVar;
    ...it comes out to...

    Code:
    MTrAllocatedObjectType<MTrAllocatedObjectType<double>> MyVar;
    ...and it interprets the ">>" as a right shift. I want it to interpret it as ending the template parameters. I tried putting spaces after the #define line, but it didn't work.

    What do I do?

  2. #2
    Registered User
    Join Date
    Oct 2005
    Posts
    16
    did you try this?
    Code:
    #define MTrAllocatedObject(Type) MTrAllocatedObjectType<Type >

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> What do I do?

    Don't use macros that way?

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Why not use a typedef:
    Code:
    typdef MTrAllocatedObjectType<MTrAllocatedObjectType<double> > MyVar;
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My C89 RANT!
    By evildave in forum C Programming
    Replies: 12
    Last Post: 12-07-2005, 10:15 PM