Click here to Skip to main content
15,123,367 members
Articles / Programming Languages / C++
Posted 29 Jun 2011

Tagged as


2 bookmarked

Passing a const character * as a template argument

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
29 Jun 2011CPOL
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[^]

template<class _Ty, const wchar_t* ptr> 
struct CVHDialogTmpl

	INT_PTR DoModal()
		return t.DoModal(ptr);
	_Ty t;

class VHRes
    static const wchar_t name[];

const wchar_t VHRes::name[] = L"XMLDlgPrj.xml";

CVHDialogTmpl<CXMLDlgPrjDlg, VHRes::name> dlg;


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


About the Author

Mukit, Ataul
Technical Lead Kotha Technologies
Bangladesh Bangladesh
If you are not in - you are out !
- Chapter 1

Comments and Discussions

GeneralBy the way symbol that starts with an underscore are usually... Pin
Philippe Mori30-Jun-11 15:11
MemberPhilippe Mori30-Jun-11 15:11 
GeneralTrying to do that might also result in code bloat... It also... Pin
Philippe Mori30-Jun-11 14:52
MemberPhilippe Mori30-Jun-11 14:52 
GeneralHi Ataul, could you elaborate a bit on where you would use s... Pin
Doc Lobster29-Jun-11 22:15
MemberDoc Lobster29-Jun-11 22:15 
GeneralRe: Thanx for pointing out the mistake, I removed the str which ... Pin
Mukit, Ataul29-Jun-11 23:26
MemberMukit, Ataul29-Jun-11 23:26 
Thanx for pointing out the mistake, I removed the str which was put there by mistake. Now to answer your real question, I tried to pass a char* as template argument and it didn't work. So this is a workaround. If you take the VHRes::name variable outside of the VHRes (i.e, make it an independant varialbe outside fo class scope) and try to initialize it and pass it, it simply won't work!! Atleast doesn't work in MS Visual Studio 2005

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.