 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Siegfried Heintze Guest
|
Posted: Fri Jan 30, 2004 8:02 pm Post subject: How do I write this function only once using templates? |
|
|
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
|
Posted: Fri Jan 30, 2004 8:32 pm Post subject: Re: How do I write this function only once using templates? |
|
|
"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
|
Posted: Sun Feb 01, 2004 8:28 pm Post subject: Re: How do I write this function only once using templates? |
|
|
"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 |
|
 |
|
|
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
|
|