Click here to Skip to main content
12,447,096 members (51,272 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

1.9K views
Posted

Passing a const character * as a template argument

, 3 Jul 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Since you must pass the string at each instanciation points, it is useless to make a template argument for it.templatestruct CVHDialogTmpl{ CVHDialogTmpl(const char *ptr_) : ptr(ptr_) { } INT_PTR DoModal() { return t.DoModal(ptr); } Ty t; ...
Since you must pass the string at each instanciation points, it is useless to make a template argument for it.

template<class>
struct CVHDialogTmpl
{     
	CVHDialogTmpl(const char *ptr_) : ptr(ptr_)
	{
	}     
 
	INT_PTR DoModal()
	{
		return t.DoModal(ptr);
	}
	
	Ty t;
        const char *ptr;
}; 

We can reuse VHRes class as defined in the original text and uses the class like this.

CVHDialogTmpl<cxmldlgprjdlg> dlg(VHRes::name);

This will works with any string including those that are built at run-time. It will be less intensive of the compiler and the generated code will probably be more efficient (memory usage).

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Philippe Mori
Software Developer (Senior)
Canada Canada
Programmer at Maid LABS from 2003 (www.maidlabs.com)

Programmer-Analyst at Viasat Geo Technoligies from 1995 to 2002 (www.viasat-geo.com).

I have studied at École Polytechnique de Montréal in computer engineering.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160811.3 | Last Updated 3 Jul 2011
Article Copyright 2011 by Philippe Mori
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid