473,388 Members | 1,209 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

forward declaration and templated class

Hi,

I have a templated class implemented in one file called CDynWnd.h
and declared like this :
CDynWnd.h (declaration and implementation)
------------

template <class BASECLASS> class CDynWnd : public BASECLASS
{

// Construction
public:
CDynWnd(int nIDD);
CDynWnd(int nIDD, CWnd* pParent);
CDynWnd();

... and so on ...
}
Now I would like to declare a new class called CDynContextMenu,
so in the .h I declare it as shown below with a forward declaration

DynContextMenu.h
-----------------
#include "DynContextMenu.h" (Only declaration)
template <class BASECLASS> class CDynWnd;
class CDynContextMenu
{

public:
CDynContextMenu();
virtual ~CDynContextMenu();

virtual CMenu* GetPopupMenu( CDynWnd<BASECLASS>* editor );

protected:
CMenu m_menu;

};

DynContextMenu.cpp (implementation)
----------------
....
....

But when I compile I get this :

Compiling...
DynContextMenu.cpp
d:\developpement\borne_300705\dyncontextmenu.h(13) : error C2065:
'BASECLASS' : undeclared identifier
Jul 31 '05 #1
1 2061
Vince wrote:
Hi,

I have a templated class implemented in one file called CDynWnd.h
and declared like this :
CDynWnd.h (declaration and implementation)
------------

template <class BASECLASS> class CDynWnd : public BASECLASS
{

// Construction
public:
CDynWnd(int nIDD);
CDynWnd(int nIDD, CWnd* pParent);
CDynWnd();

... and so on ...
}
Now I would like to declare a new class called CDynContextMenu,
so in the .h I declare it as shown below with a forward declaration

DynContextMenu.h
-----------------
#include "DynContextMenu.h" (Only declaration)
template <class BASECLASS> class CDynWnd;
class CDynContextMenu
{

public:
CDynContextMenu();
virtual ~CDynContextMenu();

virtual CMenu* GetPopupMenu( CDynWnd<BASECLASS>* editor );
The name BASECLASS does not exists by itself. It is a template
parameter which must be obtained. You do that by making the class a
template class or (probably what you want) by making this member
function a template:

template <class BASECLASS>
CMenu *GetPopupMenu(CDynWnd<BASECLASS> *editor)
{
}

Two implications: GetPopupMenu() cannot be virtual anymore and you will
probably need to define the function inline.

Think about it: you want to pass a type to CDynWnd, but you don't have
that type. If you wanted for example and int:

CMenu *GetPopupMenu(CDynWnd<int> *editor)
{
}

but since you want any type, you need to use a template, hence

template <class BASECLASS>
CMenu *GetPopupMenu(CDynWnd<BASECLASS> *editor)
{
}

Note that you could use any name:

template <class T>
CMenu *GetPopupMenu(CDynWnd<T> *editor)
{
}
protected:
CMenu m_menu;

};
But when I compile I get this :

Compiling...
DynContextMenu.cpp
d:\developpement\borne_300705\dyncontextmenu.h(13) : error C2065:
'BASECLASS' : undeclared identifier


You should read a bit more about templates before continuing. It seems
there are some basic notions you don't get.
Jonathan

Jul 31 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: mjm | last post by:
Folks, Please help me with the following problems: ******************************************** 1. I have a class template template<class Base> class Matrix : public Base { /* .... */ }
2
by: jobseeker | last post by:
From: jobseeker95479@yahoo.com (jobseeker) Newsgroups: comp.lang.c++.moderated Subject: template and forward declaration NNTP-Posting-Host: 131.233.150.22 I have defined a class that contains a...
2
by: Jorge Yáñez | last post by:
Hello, It's possible to do a forward declaration of a typedef? Something similar to typedef TMyType; // typedef forward declaration void f ( TMyType& t )
2
by: Plok Plokowitsch | last post by:
After over a decade of programming in C++ I seem to have missed some substantial point (mental note: am I getting too old for this?). A little bit of help would be *very* appreciated. I'm trying...
3
by: Michael Sgier | last post by:
Hello with the original code below I get the error: "forward declaration of `struct CPlayer'" class CPlayer; // what does this do? Instantiate the class CPlayer? // what's a forward...
11
by: Milind | last post by:
Hi, I was trying to implement a composition relation, somthing of the following type: class A { public: class B {
23
by: mark.moore | last post by:
I know this has been asked before, but I just can't find the answer in the sea of hits... How do you forward declare a class that is *not* paramaterized, but is based on a template class? ...
6
by: Hunk | last post by:
Hi I have a question on usage of forward declarations of templates. While searching through this group , people suggested using forward declarations and typedefs for templates as // in...
5
by: aaragon | last post by:
Hello, I was wondering if it is possible to forward declare a type definition. If so, what is the way to do it? I found a couple of messages where they say it's not possible but there must be a way...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.