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. Managed C++/CLI
  4. Question/problem regarding to templates in C++

Question/problem regarding to templates in C++

Scheduled Pinned Locked Moved Managed C++/CLI
questionhelpc++wpf
2 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.
  • C Offline
    C Offline
    chen_k
    wrote on last edited by
    #1

    I wrote a template class that represents objects list. This is its header:

    template< class T, char* filename >
    class obj_list
    {
    public:
    obj_list();
    virtual ~obj_list();
    void addObject(T *object);
    T getObjectAt(int i);
    void saveObjects();
    int getNumOfObjects();
    void close_file();
    private:
    CObList objects;
    POSITION pos;
    CFile objects_file;
    int numOfObjects;

    };

    When I want to create an object of the type of this class, by writing this line:

    obj_list users

    I get this error message: c:\my documents\tel_op3\tel_op3\info_dlg.h(19) : error C2964: invalid expression as template parameter that point on that line and that error message: c:\my documents\tel_op3\tel_op3\obj_list.h(13) : error C2973: 'obj_list' : invalid template argument 'filename' that point on the first line in the header (the one that conation '{') The template class passes the compile without any error message. What is wrong and how can i fix it? Thanks in advance, Chen. -- modified at 6:18 Wednesday 31st August, 2005

    T 1 Reply Last reply
    0
    • C chen_k

      I wrote a template class that represents objects list. This is its header:

      template< class T, char* filename >
      class obj_list
      {
      public:
      obj_list();
      virtual ~obj_list();
      void addObject(T *object);
      T getObjectAt(int i);
      void saveObjects();
      int getNumOfObjects();
      void close_file();
      private:
      CObList objects;
      POSITION pos;
      CFile objects_file;
      int numOfObjects;

      };

      When I want to create an object of the type of this class, by writing this line:

      obj_list users

      I get this error message: c:\my documents\tel_op3\tel_op3\info_dlg.h(19) : error C2964: invalid expression as template parameter that point on that line and that error message: c:\my documents\tel_op3\tel_op3\obj_list.h(13) : error C2973: 'obj_list' : invalid template argument 'filename' that point on the first line in the header (the one that conation '{') The template class passes the compile without any error message. What is wrong and how can i fix it? Thanks in advance, Chen. -- modified at 6:18 Wednesday 31st August, 2005

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

      use the [Modify][^] link at the bottom of your post to edit it, and the, uncheck the 'Do not treat <'s as HTML tags' check box. moreover, put the code inside a <pre></pre> block to let us benefit of the indentation...


      TOXCCT >>> GEII power
      [toxcct][VisualCalc] -- modified at 6:13 Wednesday 31st August, 2005

      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