65.9K
CodeProject is changing. Read more.
Home

Passing a const character * as a template argument

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Jun 29, 2011

CPOL
viewsIcon

34925

This tip shows you how to pass a const char* or const wchar_t* as a template argument

Many many thanks to DeadMG stack overflow http://stackoverflow.com/questions/3773378/passing-const-char-as-template-argument[^]
template<class _Ty, const wchar_t* ptr> 
struct CVHDialogTmpl
{     
	CVHDialogTmpl()
	{
	}     

	INT_PTR DoModal()
	{
		return t.DoModal(ptr);
	}
	
	_Ty t;
}; 
class VHRes
{
public:
    static const wchar_t name[];
};

const wchar_t VHRes::name[] = L"XMLDlgPrj.xml";
CVHDialogTmpl<CXMLDlgPrjDlg, VHRes::name> dlg;