Click here to Skip to main content
15,911,360 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Return variable Pin
Mukkie2-Jul-01 8:19
Mukkie2-Jul-01 8:19 
Generalxml validator Pin
1-Jul-01 23:55
suss1-Jul-01 23:55 
GeneralRe: xml validator Pin
markkuk2-Jul-01 0:46
markkuk2-Jul-01 0:46 
GeneralTemplate Question Pin
1-Jul-01 23:47
suss1-Jul-01 23:47 
GeneralRe: Template Question Pin
Martin Vladic2-Jul-01 0:26
Martin Vladic2-Jul-01 0:26 
GeneralRe: Template Question Pin
2-Jul-01 0:41
suss2-Jul-01 0:41 
GeneralRe: Template Question Pin
Martin Vladic2-Jul-01 23:30
Martin Vladic2-Jul-01 23:30 
GeneralRe: Template Question Pin
Martin Vladic2-Jul-01 23:44
Martin Vladic2-Jul-01 23:44 
I found out why some chars was stripped from my message and how to send it correctly. So, here it is, again:

It is invalid C++. Your idea written correctly looks like this:

template
class TType
{
public:
CString GetAsString()
{
CString sValue;
sValue.Format(GetFormat(), m_tValue);
return sValue;
}
protected:
T m_tValue;
};

template <class T> CString GetFormat();
template <> CString GetFormat<int>() { return "%d"; }
template <> CString GetFormat<float>() { return "%.4f"; }

Unfortunately, this doesn't work on VC++ 6.0 (GetFormat<int> is called even for float's).

Try this:

template <class T>
class TType
{
public:
TType(const T& value)
: m_tValue(value)
{
}

CString GetAsString()
{
CString sValue;
sValue.Format(TypeHelper::GetFormat(), m_tValue);
return sValue;
}

protected:
T m_tValue;
};

template <class T> class TypeHelper;

template <> class TypeHelper<int>
{
public:
static CString GetFormat() { return "%d"; }
};

template <> class TypeHelper<float>
{
public:
static CString GetFormat() { return "%.4f"; }
};

--
Martin
GeneralRe: Template Question Pin
Tomasz Sowinski2-Jul-01 1:12
Tomasz Sowinski2-Jul-01 1:12 
GeneralDisplaying Graphical Primitives of RichText Format Pin
1-Jul-01 23:26
suss1-Jul-01 23:26 
GeneralFailure in CRecordSet::IsOpen() Pin
Kristian Thelin1-Jul-01 23:09
Kristian Thelin1-Jul-01 23:09 
GeneralRe: Failure in CRecordSet::IsOpen() Pin
olof neumann1-Jul-01 23:15
olof neumann1-Jul-01 23:15 
Generaloverriding CEDIT Pin
1-Jul-01 21:43
suss1-Jul-01 21:43 
GeneralWM_CLOSE Pin
vijayaramaraju1-Jul-01 21:27
vijayaramaraju1-Jul-01 21:27 
GeneralRe: WM_CLOSE Pin
Gert Boddaert2-Jul-01 4:48
Gert Boddaert2-Jul-01 4:48 
GeneralRe: WM_CLOSE Pin
Hadi Rezaee2-Jul-01 8:29
Hadi Rezaee2-Jul-01 8:29 
GeneralRe: WM_CLOSE Pin
Jack Handy2-Jul-01 9:52
Jack Handy2-Jul-01 9:52 
GeneralRe: WM_CLOSE Pin
Hadi Rezaee2-Jul-01 10:40
Hadi Rezaee2-Jul-01 10:40 
GeneralRe: WM_CLOSE Pin
Gert Boddaert2-Jul-01 21:36
Gert Boddaert2-Jul-01 21:36 
Questionnew & modal ... stupid questions ? Pin
1-Jul-01 17:21
suss1-Jul-01 17:21 
AnswerRe: new & modal ... stupid questions ? Pin
Christian Graus1-Jul-01 18:15
protectorChristian Graus1-Jul-01 18:15 
AnswerRe: new & modal ... stupid questions ? Pin
zhenguri1-Jul-01 19:10
zhenguri1-Jul-01 19:10 
GeneralRe: new & modal ... stupid questions ? Pin
2-Jul-01 10:33
suss2-Jul-01 10:33 
General"No Disk" message. Pin
Gunter Maywald1-Jul-01 17:04
Gunter Maywald1-Jul-01 17:04 
GeneralRe: "No Disk" message. Pin
Andrew Lawrence9-Feb-10 12:10
Andrew Lawrence9-Feb-10 12:10 

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.