Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Can't compile function template on VC7.1

Can't compile function template on VC7.1

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Teerayoot
    wrote on last edited by
    #1

    i want to compile this code : template inline const T& max ( const T& a, const T& b) { return a < b ? b : a ; } got this error message : : error C2226: syntax error : unexpected type 'T' : error C2062: type 'const int' unexpected : error C2059: syntax error : ')' : error C2143: syntax error : missing ';' before '{' : error C2447: '{' : missing function header (old-style formal list?) but it's successfully compiled on BCB6.0 . VC7.1 is just stupid???

    T R 2 Replies Last reply
    0
    • T Teerayoot

      i want to compile this code : template inline const T& max ( const T& a, const T& b) { return a < b ? b : a ; } got this error message : : error C2226: syntax error : unexpected type 'T' : error C2062: type 'const int' unexpected : error C2059: syntax error : ')' : error C2143: syntax error : missing ';' before '{' : error C2447: '{' : missing function header (old-style formal list?) but it's successfully compiled on BCB6.0 . VC7.1 is just stupid???

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #2

      Teerayoot wrote: template inline const T& max ( const T& a, const T& b) { return a < b ? b : a ; } put above code in header file !

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      cheers, Alok Gupta

      1 Reply Last reply
      0
      • T Teerayoot

        i want to compile this code : template inline const T& max ( const T& a, const T& b) { return a < b ? b : a ; } got this error message : : error C2226: syntax error : unexpected type 'T' : error C2062: type 'const int' unexpected : error C2059: syntax error : ')' : error C2143: syntax error : missing ';' before '{' : error C2447: '{' : missing function header (old-style formal list?) but it's successfully compiled on BCB6.0 . VC7.1 is just stupid???

        R Offline
        R Offline
        Rahim Rattani
        wrote on last edited by
        #3

        try using as template<typename T> inline const T& getMax ( const T& a, const T& b) { return a < b ? b : a ; } The problem is with the name of the function. I have renamed it from "max" to "getMax" because macros with the name "min" and "max" already exist in stdlib.h, and same name of the function as those macros caused the errors. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan

        T 1 Reply Last reply
        0
        • R Rahim Rattani

          try using as template<typename T> inline const T& getMax ( const T& a, const T& b) { return a < b ? b : a ; } The problem is with the name of the function. I have renamed it from "max" to "getMax" because macros with the name "min" and "max" already exist in stdlib.h, and same name of the function as those macros caused the errors. Rahim Rattani Software Engineer, Matrix Systems (Pvt) Ltd., Karachi - Pakistan

          T Offline
          T Offline
          Teerayoot
          wrote on last edited by
          #4

          Error message make me very confuse. it should say "name of the function max alredy exist in standard library!" or somethings that can make sense. :) Thank you.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups