473,387 Members | 1,624 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,387 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 1616
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: 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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.