473,323 Members | 1,560 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,323 software developers and data experts.

templated class

Hi,

I would need some help to write a templated function or method.
I am developping a GUI and on one plateform I am using a listbox
(CListBox) while on the other it's a combobox(CCombobox).
Both controls derived from a the same base class CWnd like this :

class CComboBox : public CWnd
{
....
int AddString(LPCTSTR lpszString);
}

class CListBox : public CWnd
{
....
int AddString(LPCTSTR lpszItem);
}
in my dialog I would like to write a method that take a CComboBox or a
CListBox and call the AddString method.

class CMyDialog : public CDialog
{
// take a CListBox or CCombobox
template<typename TList>
int AddListEntry(Tlist& List, LPCTSTR tszText, DWORD dwItemData);
void OnInitDialog()
{
AddListEntry(m_ListCtl, "eze", 0);
}

#ifdef PLATFORM1
CCombobox m_ListCtl;
#else
CListBox m_ListCtl;
#endif
};

How can I do that ?
Mar 24 '07 #1
1 1614
On 2007-03-24 15:40, Vincent RICHOMME wrote:
Hi,

I would need some help to write a templated function or method.
I am developping a GUI and on one plateform I am using a listbox
(CListBox) while on the other it's a combobox(CCombobox).
Both controls derived from a the same base class CWnd like this :

class CComboBox : public CWnd
{
...
int AddString(LPCTSTR lpszString);
}

class CListBox : public CWnd
{
...
int AddString(LPCTSTR lpszItem);
}
in my dialog I would like to write a method that take a CComboBox or a
CListBox and call the AddString method.

class CMyDialog : public CDialog
{
// take a CListBox or CCombobox
template<typename TList>
int AddListEntry(Tlist& List, LPCTSTR tszText, DWORD dwItemData);
void OnInitDialog()
{
AddListEntry(m_ListCtl, "eze", 0);
}

#ifdef PLATFORM1
CCombobox m_ListCtl;
#else
CListBox m_ListCtl;
#endif
};
You shouldn't need any macros to do this, (though I think you can use
macros and skip the templates). What you have above looks good to me,
just implement the AddListEntry() method and you should be good to go:

template<typename TList>
int CMyDialog::AddListEntry(TList& List, LPCTSTR tszText, DWORD dwItemData)
{
List.addString(tszText);
// ...
}

--
Erik Wikström
Mar 24 '07 #2

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

Similar topics

3
by: tirath | last post by:
Hi all, I have a templated class that derives from a non-templated abstract class. How do I then cast a base class pointer to a <templated> derived class pointer in a generalised fashion? ...
1
by: Rich | last post by:
Hi, I have a query regarding VC6 and its handling of templated copy constructors. Here goes: Take a look at the following code sample... template<class _Ty, size_t t_uiSize = 10 > class...
2
by: ferdinand.stefanus | last post by:
Hi, I have some questions regarding templated class constructor: #include <iostream> using namespace std; template<typename T> class Foo { public:
9
by: Jon Wilson | last post by:
I have a class which needs to accumulate data. The way we get this data is by calling a member function which returns float on a number of different objects of different type (they are all the...
4
by: Lionel B | last post by:
Greetings, The following code: <code> template<typename T> class A { protected:
6
by: __PPS__ | last post by:
it's ok according to the standard to specialize member function like this: template<class T>struct xxx { void func(); }; template<>bool xxx<int>::func(){ //int version } template<>bool...
2
by: mattjgalloway | last post by:
I'm having some problems with a templated member function of a templated class. Unfortunately I can't replicate it with a simple example so I know something odd must be going on!!! Basically it's...
7
by: Claudius | last post by:
Hello, in my class TopTen I need to define three constructors while only the last one, the most general in terms of templates, should be sufficient in my opinion: template <typename Tnum,...
2
by: domehead100 | last post by:
I have a templated class, CDerived: template <typename TValue, typename TDraw, typename TEdit ...> class CDerived : public CBase { TValue m_Value public: TValue& GetValue() const {
2
card
by: card | last post by:
Hi everyone, I have a question about referencing a nested class contained within a templated class. Of course the best way to show you is by example. Here's my templated classes: #include...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.