473,241 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

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;
}
Jul 22 '05 #1
2 2047

"Siegfried Heintze" <si*******@heintze.com> wrote in message
news:40********@news.seqnet.net...
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<typename Ch, typename Tr>
friend std::basic_ostream<Ch, Tr>& operator<<
(std::basic_ostream<Ch, Tr>& out, DVDDeltaTime) { /* ... */ }

Be aware that not all compilers are happy with this.

Jonathan
Jul 22 '05 #2
"Siegfried Heintze" <si*******@heintze.com> wrote in
news:40********@news.seqnet.net:

(...)
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
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: David Furey | last post by:
Hi I have an XML documnet and a XSLT document as shown below THe XSLT document brings back a filtered docmument that has the VendorName that starts with a particular sub-string This works as...
9
by: Fred H | last post by:
I'm currently trying to write a function template that can fill a variable of arbitrary type with 'random' stuff, but I can't seem to get my function template working. In my .h file I've...
7
by: Hendrik Schober | last post by:
Hi, I have a problem, that boils down to the following code: #include <iostream> #include <typeinfo> class Test1 {}; class Test2 {}; class Test3 {};
5
by: Levent | last post by:
Hi, Why doesn't this work? (tried with gcc 3.3.3 and VC++ 7.1): #include <iostream> template<class T, unsigned N> struct Foo { void func(); }; template<class T, unsigned N>
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
18
by: jacob navia | last post by:
In C, we have read-only memory (const), read/write memory (normal data), and write only memory. Let's look at the third one in more detail. Write only memory is a piece of RAM that can only...
10
by: roberts.noah | last post by:
Using ostringstream the buffer gets increased to allow data to be appended when needed at least when you call <<. I was under the impression that write() also did but I am having problems that...
13
by: mike b | last post by:
Hello everyone, thanks in advance for your help. I'm new to C++ templates and have run into some issues using member function templates. I have a shared library containing templates that I'm...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.