473,799 Members | 3,190 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ~CDynContextMen u();

virtual CMenu* GetPopupMenu( CDynWnd<BASECLA SS>* editor );

protected:
CMenu m_menu;

};

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

But when I compile I get this :

Compiling...
DynContextMenu. cpp
d:\developpemen t\borne_300705\ dyncontextmenu. h(13) : error C2065:
'BASECLASS' : undeclared identifier
Jul 31 '05 #1
1 2075
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 ~CDynContextMen u();

virtual CMenu* GetPopupMenu( CDynWnd<BASECLA SS>* 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(C DynWnd<BASECLAS S> *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(C DynWnd<int> *editor)
{
}

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

template <class BASECLASS>
CMenu *GetPopupMenu(C DynWnd<BASECLAS S> *editor)
{
}

Note that you could use any name:

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

};
But when I compile I get this :

Compiling...
DynContextMenu. cpp
d:\developpemen t\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
5469
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
14156
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 data member of a function type. The signature of the function type take a pointer of the class itself as a parameter: class Softkey; // forward declaration
2
1873
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
4521
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 to gather various different classes into a common namespace using typedefs: class QWidget {}; class MyListview {}; namespace gui
3
20615
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 declaration? class CEnemy : public CEntity { public:
11
2812
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
3868
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? Here's what I thought should work, but apparently doesn't: class Foo; void f1(Foo* p)
6
8620
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 myfile.h template<typename T,typename R> class some_class;
5
7010
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 to do it. Thank you. a²
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10214
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10023
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9067
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7561
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2935
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.