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. Class template argment list

Class template argment list

Scheduled Pinned Locked Moved C / C++ / MFC
c++htmlcsswpfhelp
4 Posts 4 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.
  • O Offline
    O Offline
    Oliver123
    wrote on last edited by
    #1

    NOTE: In the following text and code I use [] rather than the greater than and less than signs because of the HTML editor. I read about class templates in three books and MSDN and thought I understood. So, I created a SDI test project in VC++ to learn about them. I added only this single CTestTemp class. As you can see, I didn't get far. The following code keeps giving me a C2955 (use of class template requires template argument list) error in TestTemp.cpp each place a function is defined (or BEGIN MESSAGE MAP). I have tried all kinds of argument lists in the constructor function, tried putting template[class T] in various places in the code, but nothing works. If I add a new function, the same error flags the new function. It appears I'm doing somehting wrong in the function definition. I'm at such a basic point, I figure I must be doing somehting equally basic wrong. Ideas? Thanks. //TestTemp.h template[class T] <--only thing I add class CTestTemp : public CWnd { public: CTestTemp(); virtual ~CTestTemp(); protected: DECLARE_MESSAGE_MAP() }; //TestTemp.cpp CTestTemp::CTestTemp() <---error C2955 { } CTestTemp::~CTestTemp() <---error C2955 { } BEGIN_MESSAGE_MAP(CTestTemp, CWnd) <---error C2955 //{{AFX_MSG_MAP(CTestTemp) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAP END_MESSAGE_MAP()

    C M J 3 Replies Last reply
    0
    • O Oliver123

      NOTE: In the following text and code I use [] rather than the greater than and less than signs because of the HTML editor. I read about class templates in three books and MSDN and thought I understood. So, I created a SDI test project in VC++ to learn about them. I added only this single CTestTemp class. As you can see, I didn't get far. The following code keeps giving me a C2955 (use of class template requires template argument list) error in TestTemp.cpp each place a function is defined (or BEGIN MESSAGE MAP). I have tried all kinds of argument lists in the constructor function, tried putting template[class T] in various places in the code, but nothing works. If I add a new function, the same error flags the new function. It appears I'm doing somehting wrong in the function definition. I'm at such a basic point, I figure I must be doing somehting equally basic wrong. Ideas? Thanks. //TestTemp.h template[class T] <--only thing I add class CTestTemp : public CWnd { public: CTestTemp(); virtual ~CTestTemp(); protected: DECLARE_MESSAGE_MAP() }; //TestTemp.cpp CTestTemp::CTestTemp() <---error C2955 { } CTestTemp::~CTestTemp() <---error C2955 { } BEGIN_MESSAGE_MAP(CTestTemp, CWnd) <---error C2955 //{{AFX_MSG_MAP(CTestTemp) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAP END_MESSAGE_MAP()

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      you need, at least, to put 'T' into your constructor: CTestTemp(T t); without it, you have no way to tell the compiler what type to use for T

      image processing toolkits | batch image processing

      1 Reply Last reply
      0
      • O Oliver123

        NOTE: In the following text and code I use [] rather than the greater than and less than signs because of the HTML editor. I read about class templates in three books and MSDN and thought I understood. So, I created a SDI test project in VC++ to learn about them. I added only this single CTestTemp class. As you can see, I didn't get far. The following code keeps giving me a C2955 (use of class template requires template argument list) error in TestTemp.cpp each place a function is defined (or BEGIN MESSAGE MAP). I have tried all kinds of argument lists in the constructor function, tried putting template[class T] in various places in the code, but nothing works. If I add a new function, the same error flags the new function. It appears I'm doing somehting wrong in the function definition. I'm at such a basic point, I figure I must be doing somehting equally basic wrong. Ideas? Thanks. //TestTemp.h template[class T] <--only thing I add class CTestTemp : public CWnd { public: CTestTemp(); virtual ~CTestTemp(); protected: DECLARE_MESSAGE_MAP() }; //TestTemp.cpp CTestTemp::CTestTemp() <---error C2955 { } CTestTemp::~CTestTemp() <---error C2955 { } BEGIN_MESSAGE_MAP(CTestTemp, CWnd) <---error C2955 //{{AFX_MSG_MAP(CTestTemp) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAP END_MESSAGE_MAP()

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Fixing the constructor/destructor syntax is one thing. I'm not sure how you're going to get a template class through the CWnd message map macros though...

        //TestTemp.h
        template <class T>
        class CTestTemp : public CWnd
        {
        public:
            CTestTemp();
            virtual ~CTestTemp();

        protected:
            DECLARE_MESSAGE_MAP()
        };

        //TestTemp.cpp
        template <class T> CTestTemp<T>::CTestTemp()
        {
        }
        template <class T> CTestTemp<T>::~CTestTemp()
        {
        }

        // I don't know how to make this next part work!
        BEGIN_MESSAGE_MAP(CTestTemp<int>, CWnd)
        //{{AFX_MSG_MAP(CTestTemp)
        // NOTE - the ClassWizard will add and remove mapping macros here.
        //}}AFX_MSG_MAP
        END_MESSAGE_MAP()

        Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        1 Reply Last reply
        0
        • O Oliver123

          NOTE: In the following text and code I use [] rather than the greater than and less than signs because of the HTML editor. I read about class templates in three books and MSDN and thought I understood. So, I created a SDI test project in VC++ to learn about them. I added only this single CTestTemp class. As you can see, I didn't get far. The following code keeps giving me a C2955 (use of class template requires template argument list) error in TestTemp.cpp each place a function is defined (or BEGIN MESSAGE MAP). I have tried all kinds of argument lists in the constructor function, tried putting template[class T] in various places in the code, but nothing works. If I add a new function, the same error flags the new function. It appears I'm doing somehting wrong in the function definition. I'm at such a basic point, I figure I must be doing somehting equally basic wrong. Ideas? Thanks. //TestTemp.h template[class T] <--only thing I add class CTestTemp : public CWnd { public: CTestTemp(); virtual ~CTestTemp(); protected: DECLARE_MESSAGE_MAP() }; //TestTemp.cpp CTestTemp::CTestTemp() <---error C2955 { } CTestTemp::~CTestTemp() <---error C2955 { } BEGIN_MESSAGE_MAP(CTestTemp, CWnd) <---error C2955 //{{AFX_MSG_MAP(CTestTemp) // NOTE - the ClassWizard will add and remove mapping macros here. //}}AFX_MSG_MAP END_MESSAGE_MAP()

          J Offline
          J Offline
          Jheriko
          wrote on last edited by
          #4

          The problem with templates is that you can't have the definition in a .h and the implementation in .cpp Templates are like macros in that they are processed before the compilaton proper. There is a reason that I can't remember why that causes the problem... something to do with operating at the file scope rather than program scope There are a few ways around it, one is to write everything into the class defintion in the .h file. Contrary to popular belief this will not stop your code from working, but it is generally not good practice. There are some more elaborate workarounds out there if you look on Google... Hope this helps.

          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