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. template problems

template problems

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
4 Posts 2 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.
  • P Offline
    P Offline
    pankajdaga
    wrote on last edited by
    #1

    Hi everyone, I am having problems trying to use a templated function. I have a templated function like so: template bool SetCellStyle(int row, int column, const T & value) Now I call the function like this for example: void MyFunc(int value) { objectPointer->SetCellStyle(row, column, value); } This results in the following error: error C2275: 'int' : illegal use of this type as an expression. I do not know why I am not allowed to do this. I would really appreciate some help here. Thanks, Pankaj /** I'm the one who's gonna have to die When it's time for me to die So let me live my life The way I want to - Jimi Hendrix */

    J 2 Replies Last reply
    0
    • P pankajdaga

      Hi everyone, I am having problems trying to use a templated function. I have a templated function like so: template bool SetCellStyle(int row, int column, const T & value) Now I call the function like this for example: void MyFunc(int value) { objectPointer->SetCellStyle(row, column, value); } This results in the following error: error C2275: 'int' : illegal use of this type as an expression. I do not know why I am not allowed to do this. I would really appreciate some help here. Thanks, Pankaj /** I'm the one who's gonna have to die When it's time for me to die So let me live my life The way I want to - Jimi Hendrix */

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      Hello, first of all please turn the "Do not treat <'s as HTML tags" checkbox on when posting code, so that <s are shown properly. I reproduce here your code (with brackets):

      template <class T>
      bool SetCellStyle(int row, int column, const T & value)

      void MyFunc(int value)
      {
      objectPointer->SetCellStyle<int>(row, column, value);
      }

      Is MyFunc by chance a member function of a class template? If so, maybe you're being hit by a nasty problem with so called dependent contexts. Please try the following and report the results:

      void MyFunc(int value)
      {
      objectPointer-> template SetCellStyle<int>(row, column, value);
      }

      Did that work? Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]!

      1 Reply Last reply
      0
      • P pankajdaga

        Hi everyone, I am having problems trying to use a templated function. I have a templated function like so: template bool SetCellStyle(int row, int column, const T & value) Now I call the function like this for example: void MyFunc(int value) { objectPointer->SetCellStyle(row, column, value); } This results in the following error: error C2275: 'int' : illegal use of this type as an expression. I do not know why I am not allowed to do this. I would really appreciate some help here. Thanks, Pankaj /** I'm the one who's gonna have to die When it's time for me to die So let me live my life The way I want to - Jimi Hendrix */

        J Offline
        J Offline
        Joaquin M Lopez Munoz
        wrote on last edited by
        #3

        Oh, also, you don't really need the <int> part here. The following should suffice:

        void MyFunc(int value)
        {
        objectPointer->SetCellStyle(row, column, value);
        }

        Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]!

        P 1 Reply Last reply
        0
        • J Joaquin M Lopez Munoz

          Oh, also, you don't really need the <int> part here. The following should suffice:

          void MyFunc(int value)
          {
          objectPointer->SetCellStyle(row, column, value);
          }

          Joaquín M López Muñoz Telefónica, Investigación y Desarrollo Want a Boost forum in Code Project? Vote here[^]!

          P Offline
          P Offline
          pankajdaga
          wrote on last edited by
          #4

          Hi! Thanks. The whole problem was the in the call. It behaves ok when I use objectPointer->SetCellStyle(row, column, value) instead of objectPointer->SetCellStyle(row, column, value); I have no idea why. I thought after VS 5.0 this problem disappeared. I am going to try it with VS 7 to see what happens. Cheers, Pankaj /** I'm the one who's gonna have to die When it's time for me to die So let me live my life The way I want to - Jimi Hendrix */

          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