473,386 Members | 2,042 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,386 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 2052

"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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.