Is this possible with a template?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jamie Burns

    Is this possible with a template?

    Hello,

    I have an application which uses a class called "rSharedPointer ". I want to
    replace it with the Boost shared pointer but would like to keep the old name
    and not modify any existing code.

    I have tried doing the following:

    typedef boost::shared_p tr<T> rSharedPointer;

    and:

    template<typena me T> typedef boost::shared_p tr<T> rSharedPointer;

    But it will not compile?

    Any ideas?

    Jamie.


  • Victor Bazarov

    #2
    Re: Is this possible with a template?

    "Jamie Burns" <reply_to_group @whatever.com> wrote...[color=blue]
    > I have an application which uses a class called "rSharedPointer ". I want
    > to replace it with the Boost shared pointer but would like to keep the old
    > name and not modify any existing code.
    >
    > I have tried doing the following:
    >
    > typedef boost::shared_p tr<T> rSharedPointer;
    >
    > and:
    >
    > template<typena me T> typedef boost::shared_p tr<T> rSharedPointer;
    >
    > But it will not compile?
    >
    > Any ideas?[/color]

    If 'rSharedPointer ' is a _class_, you cannot replace it with a template
    in your code, the use for classes and templates is different. So, even
    if there were (and there isn't) support for template typedefs, how would
    you then use your 'rSharedPointer '?

    If, contrary to your own words, 'rSharedPointer ' is, in fact, a template,
    then you could try using a macro:

    #define rSharedPointer boost::shared_p tr

    V


    Comment

    • Jamie Burns

      #3
      Re: Is this possible with a template?

      Thanks Victor.

      Yes, it was a template, not a class!

      The #define works a treat :o)

      Jamie.

      "Victor Bazarov" <v.Abazarov@com Acast.net> wrote in message
      news:6BgBd.5947 03$wV.391026@at tbi_s54...[color=blue]
      > "Jamie Burns" <reply_to_group @whatever.com> wrote...[color=green]
      >> I have an application which uses a class called "rSharedPointer ". I want
      >> to replace it with the Boost shared pointer but would like to keep the
      >> old name and not modify any existing code.
      >>
      >> I have tried doing the following:
      >>
      >> typedef boost::shared_p tr<T> rSharedPointer;
      >>
      >> and:
      >>
      >> template<typena me T> typedef boost::shared_p tr<T> rSharedPointer;
      >>
      >> But it will not compile?
      >>
      >> Any ideas?[/color]
      >
      > If 'rSharedPointer ' is a _class_, you cannot replace it with a template
      > in your code, the use for classes and templates is different. So, even
      > if there were (and there isn't) support for template typedefs, how would
      > you then use your 'rSharedPointer '?
      >
      > If, contrary to your own words, 'rSharedPointer ' is, in fact, a template,
      > then you could try using a macro:
      >
      > #define rSharedPointer boost::shared_p tr
      >
      > V
      >[/color]


      Comment

      • Andrey Tarasevich

        #4
        Re: Is this possible with a template?

        Jamie Burns wrote:[color=blue]
        > ...
        > I have an application which uses a class called "rSharedPointer ". I want to
        > replace it with the Boost shared pointer but would like to keep the old name
        > and not modify any existing code.
        >
        > I have tried doing the following:
        >
        > typedef boost::shared_p tr<T> rSharedPointer;
        >
        > and:
        >
        > template<typena me T> typedef boost::shared_p tr<T> rSharedPointer;
        >
        > But it will not compile?
        >
        > Any ideas?
        > ...[/color]

        It looks like you need a template 'typedef'. C++ doesn't have template
        'typedef's, but there is a well-known idiom that comes pretty close

        template<typena me T> struct rSharedPointer {
        typedef boost::shared_p tr<T> type;
        };

        However, in this case you'll have to declare your 'rSharedPointer 's as
        follows

        rSharedPointer< int>::type ptr;

        This is probably different from what you currently have. If this is
        unacceptable for you, you'll probably have to stick with
        preprocessor-based solution suggested by Victor.

        --
        Best regards,
        Andrey Tarasevich

        Comment

        Working...