Utilisation des templates
Bonjour à tous,
J'ai décidé d'utiliser les templates pour créer une classe super générique.
Mais j'ai un soucis au niveau de la compilation. Voici l'erreur
Citation:
Compiling...
DockViewBar.cpp
D:\DEV_ROOT\Lib\ControlsLib\DockViewBar.cpp(31) : error C2955: 'CDockViewBar' : use of class template requires template argument list
d:\dev_root\lib\controlslib\dockviewbar.h(47) : see declaration of 'CDockViewBar'
D:\DEV_ROOT\Lib\ControlsLib\DockViewBar.cpp(31) : error C2955: 'CDockViewBar' : use of class template requires template argument list
d:\dev_root\lib\controlslib\dockviewbar.h(47) : see declaration of 'CDockViewBar'
Je comprend bien le message d'erreur. Il faut que je mette un template <class TPL_VIEW>, mais le compilateur ne veux rien savoir.
Voici le code de ma petite classe:
DockViewBar.h
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #if !defined(AFX_DOCKVIEWBAR_H__A00CEEA4_3F10_4794_A834_82C511FA6DC9__INCLUDED_)
#define AFX_DOCKVIEWBAR_H__A00CEEA4_3F10_4794_A834_82C511FA6DC9__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DockViewBar.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CDockViewBar window
template <class TPL_VIEW>
class CDockViewBar : public baseCDockViewBar
{
// Construction
public:
CDockViewBar(CCreateContext* pContext =NULL);
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CPageSettingFieldsBar)
//}}AFX_VIRTUAL
// Implementation
public:
CCreateContext * GetCreateContext ( );
virtual ~CDockViewBar();
// Generated message map functions
protected:
TPL_VIEW * m_pView;
CCreateContext * m_pContext;
virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
//{{AFX_MSG(CPageSettingFieldsBar)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#endif //AFX_DOCKVIEWBAR_H__A00CEEA4_3F10_4794_A834_82C511FA6DC9__INCLUDED_ |
DockViewBar.cpp
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| // DockViewBar.cpp : implementation file
//
#include "stdafx.h"
#include "DockViewBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDockViewBar
template <class TPL_VIEW>
CDockViewBar<TPL_VIEW>::CDockViewBar(CCreateContext* pContext /* =NULL*/ )
{
m_pContext = pContext;
// Création de la vue en outrepassant le constructeur "protected"
CRuntimeClass* pFactory = RUNTIME_CLASS(TPL_VIEW);
m_pView = pFactory->CreateObject ( );
}
template <class TPL_VIEW>
CDockViewBar<TPL_VIEW>::~CDockViewBar()
{
}
BEGIN_MESSAGE_MAP(CDockViewBar, baseCDockViewBar)
//{{AFX_MSG_MAP(CDockViewBar)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDockViewBar message handlers
template <class TPL_VIEW>
int CDockViewBar<TPL_VIEW>::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (baseCDockViewBar::OnCreate(lpCreateStruct) == -1)
return -1;
SetSCBStyle(GetSCBStyle() | SCBS_SIZECHILD);
if (m_pView )
{
m_pView->CreateView(this, m_pContext);
}
return 0;
}
template <class TPL_VIEW>
void CDockViewBar<TPL_VIEW>::OnUpdateCmdUI(CFrameWnd* pTarget,
BOOL bDisableIfNoHndler)
{
pTarget->ShowControlBar(this,TRUE,FALSE);
UNUSED_ALWAYS(bDisableIfNoHndler);
} |
A oui autre petit détails qui a son importance. L'erreur se produit sur le
BEGIN_MESSAGE_MAP(CDockViewBar, baseCDockViewBar)
Si vous aviez une petite idée, j'avoue que ça m'arrangerai
Merci d'avance