C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How do I write this function only once using templates?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Siegfried Heintze
Guest





PostPosted: Fri Jan 30, 2004 8:02 pm    Post subject: How do I write this function only once using templates? Reply with quote



How do I use a template to write these friend functions once? The are nearly
identical. Also, why does wcout << L'A'; print 65 instead of a character?
Thanks,
Siegfried

struct DVDDeltaTime{
// constructors go here...
friend std::ostream & operator<<(std::ostream &os, const DVDDeltaTime&
dt ){
return os
<< ' ' << std::setw(2) << std::setfill('0') << dt.m_nTitles
<< ':' << std::setw(2) << std::setfill('0') << dt.m_nHours
<< ':' << std::setw(2) << std::setfill('0') << dt.m_nMinutes
<< ':' << std::setw(2) << std::setfill('0') << dt.m_nSeconds
<< ':' << std::setw(2) << std::setfill('0') << dt.m_nFrames;
}
friend std::wostream & operator<<(std::wostream &os, const DVDDeltaTime&
dt ){
return os
<< L" " << std::setw(2) << std::setfill(L'0') << dt.m_nTitles
<< L":" << std::setw(2) << std::setfill(L'0') << dt.m_nHours
<< L":" << std::setw(2) << std::setfill(L'0') << dt.m_nMinutes
<< L":" << std::setw(2) << std::setfill(L'0') << dt.m_nSeconds
<< L":" << std::setw(2) << std::setfill(L'0') << dt.m_nFrames ;
}
private:
unsigned m_nTitles:8, m_nHours:6, m_nMinutes:6, m_nSeconds:6,
m_nFrames:6;
}


Back to top
Jonathan Turkanis
Guest





PostPosted: Fri Jan 30, 2004 8:32 pm    Post subject: Re: How do I write this function only once using templates? Reply with quote




"Siegfried Heintze" <siegfried (AT) heintze (DOT) com> wrote

Quote:
How do I use a template to write these friend functions once? The
are nearly
identical. Also, why does wcout << L'A'; print 65 instead of a
character?
Thanks,
Siegfried

template friend std::basic_ostream<Ch, Tr>& operator<<
(std::basic_ostream
Be aware that not all compilers are happy with this.

Jonathan



Back to top
bartek
Guest





PostPosted: Sun Feb 01, 2004 8:28 pm    Post subject: Re: How do I write this function only once using templates? Reply with quote



"Siegfried Heintze" <siegfried (AT) heintze (DOT) com> wrote in
news:401ab90e$1 (AT) news (DOT) seqnet.net:

(...)

Quote:
Also, why does wcout << L'A'; print 65 instead of a
character?

It's actually off topic... but anyway...
This is a "MSVC++ Specific Behaviour(TM)" - they don't sport wchar_t as a
unique type, but rather a typedef from unsigned short. poof!

Cheers,
b

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.