typename usege problem ...

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

    #1

    typename usege problem ...

    Hi all,
    I have this member in a template class:

    bool opsInsert(int nId, T pObj){
    pairRet = insert(typename std::map<int,T> ::value_type(nI d, pObj)); }

    which does compile with gcc but not with cl.exe (Windows).
    If I remove the typename keyword, the code does not compile with gcc,
    but compiles witc cl.exe....

    The question: which is the standard way to call this function? Is there
    any workaround to make compile with both compilers?

    I know this is a compiler issue, but I hope you will help me ...

    thanx,
    stefan

  • Rolf Magnus

    #2
    Re: typename usege problem ...

    466 wrote:
    Hi all,
    I have this member in a template class:
    >
    bool opsInsert(int nId, T pObj){
    pairRet = insert(typename std::map<int,T> ::value_type(nI d, pObj)); }
    >
    which does compile with gcc but not with cl.exe (Windows).
    If I remove the typename keyword, the code does not compile with gcc,
    but compiles witc cl.exe....
    >
    The question: which is the standard way to call this function?
    The standard requires the typename keyword in this place.
    Is there any workaround to make compile with both compilers?
    Maybe use a macro, like:

    #if compiler is vc++
    #define TYPENAME
    #else
    #define TYPENAME typename
    #endif

    bool opsInsert(int nId, T pObj){
    pairRet = insert(TYPENAME std::map<int,T> ::value_type(nI d, pObj)); }

    It's ugly, but works.

    Comment

    • 466

      #3
      Re: typename usege problem ...


      Rolf Magnus wrote:
      466 wrote:
      >
      Hi all,
      I have this member in a template class:

      bool opsInsert(int nId, T pObj){
      pairRet = insert(typename std::map<int,T> ::value_type(nI d, pObj)); }

      which does compile with gcc but not with cl.exe (Windows).
      If I remove the typename keyword, the code does not compile with gcc,
      but compiles witc cl.exe....

      The question: which is the standard way to call this function?
      >
      The standard requires the typename keyword in this place.
      >
      Is there any workaround to make compile with both compilers?
      >
      Maybe use a macro, like:
      >
      #if compiler is vc++
      #define TYPENAME
      #else
      #define TYPENAME typename
      #endif
      >
      bool opsInsert(int nId, T pObj){
      pairRet = insert(TYPENAME std::map<int,T> ::value_type(nI d, pObj)); }
      >
      It's ugly, but works.
      Sure, as a ultimate solution ... :(
      Thanx.

      Comment

      • Ron Natalie

        #4
        Re: typename usege problem ...

        466 wrote:
        Hi all,
        I have this member in a template class:
        >
        bool opsInsert(int nId, T pObj){
        pairRet = insert(typename std::map<int,T> ::value_type(nI d, pObj)); }
        >
        which does compile with gcc but not with cl.exe (Windows).
        If I remove the typename keyword, the code does not compile with gcc,
        but compiles witc cl.exe....
        >
        Get a version of the windows compiler that was published in the last
        five years.

        Comment

        • jim_taylor

          #5
          Re: typename usege problem ...

          Maybe use a macro, like:
          >
          #if compiler is vc++
          #define TYPENAME
          #else
          #define TYPENAME typename
          #endif
          >
          You could use the macro
          #define typename
          as basically the older compilers don't know the typename keyword.
          Be careful to make your #if specific to the current (and older)
          versions of your compiler, as you don't want it to break when you do
          upgrade...
          Note also that the standard also allows typename as a synonym
          (basically) for class in the template arguments,which also will not
          work in yuour old compiler. i.e. you can write
          template <typename MyType>

          Comment

          • Bo Persson

            #6
            Re: typename usege problem ...

            jim_taylor wrote:
            >Maybe use a macro, like:
            >>
            >#if compiler is vc++
            >#define TYPENAME
            >#else
            >#define TYPENAME typename
            >#endif
            >>
            >
            You could use the macro
            #define typename
            as basically the older compilers don't know the typename keyword.
            Except that in this case we recognize a certain compiler, that requires
            typename in some places, doesn't care in other places, and flat out refuses
            to recognize some cases where typename *is* required.

            A very useful advice - use a compiler from this millennium - has alredy been
            given by another poster.


            Bo Persson


            Comment

            • Mark P

              #7
              Re: typename usege problem ...

              466 wrote:
              Hi all,
              I have this member in a template class:
              >
              bool opsInsert(int nId, T pObj){
              pairRet = insert(typename std::map<int,T> ::value_type(nI d, pObj)); }
              >
              which does compile with gcc but not with cl.exe (Windows).
              If I remove the typename keyword, the code does not compile with gcc,
              but compiles witc cl.exe....
              >
              The question: which is the standard way to call this function? Is there
              any workaround to make compile with both compilers?
              >
              I know this is a compiler issue, but I hope you will help me ...
              >
              thanx,
              stefan
              >
              As has been noted, the standard requires "typename". However you could
              replace the expression by the actual type of value_type, namely
              std::pair< const int, T>. That should not require "typename".

              Comment

              Working...