473,396 Members | 1,726 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,396 software developers and data experts.

Problem of template

swh
Hello.I'm start to write some templates,but I have some questions about
them.

#include <iostream>
using namespace std;

template<typename Tvoid f(T const& a) {
cout << "Primary" << endl;
}

void f(int const& a) {
cout << "Non-template" << endl;
}

template<void f(int const& a) {
cout << "Full" << endl;
}

int main() {
f(1.0); // line 1
f(1); // line 2
f<>(1); // line 3
}

The result is:
Primary
Non-template
Non-template

I don't understand the third line in main().I have specified the angle
brackets after the f,
but the resulting call is the Non-template version.Why?

Jul 8 '06 #1
2 1083
swh wrote:
Hello.I'm start to write some templates,but I have some questions
about them.

#include <iostream>
using namespace std;

template<typename Tvoid f(T const& a) {
cout << "Primary" << endl;
}

void f(int const& a) {
cout << "Non-template" << endl;
}

template<void f(int const& a) {
cout << "Full" << endl;
}

int main() {
f(1.0); // line 1
f(1); // line 2
f<>(1); // line 3
}

The result is:
Primary
Non-template
Non-template

I don't understand the third line in main().I have specified the angle
brackets after the f,
but the resulting call is the Non-template version.Why?
I can only speculate that it's a bug in the compiler. Have you
tried a different compiler?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 8 '06 #2
swh
I can only speculate that it's a bug in the compiler. Have you
tried a different compiler?
Thanks, I have tried another complier and everything was OK.

Jul 8 '06 #3

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

Similar topics

2
by: nanookfan | last post by:
Hi all, I'm having a bizarre problem converting XML files to HTML using an XSLT. The problem is only occuring in my Netscape 7.0 browser. What makes it more bizarre is that it is only...
7
by: Andy Fish | last post by:
Hi, I'm stuck with an XSL problem - can anyone give me any hints? I have some XML with nested formatting tags like this: <text> this is plain <bold> this is bold
5
by: Clifford W. Racz | last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the...
2
by: littlefitzer | last post by:
Hi, I have come across a tricky little problem, I hope maybe one of you can help. The problem I am having is that I need to parse two seperate values from an XML document using XSL. The two...
4
by: C. Carbonera | last post by:
/* Hi, I have a problem with explicit instantiation of templates in Visual C++ 6.0. I have provided the source below. I have an example of a function template that produces incorrect output in...
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 {};
7
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
9
by: Prasad | last post by:
HI, I am a beginner in VC++.. I am trying to write a Win32 console application in visual studio.. I am using following header files.. #include <STRING> using namespace std; #include...
7
by: StephQ | last post by:
First of all: distinction of keywords typename and class in template arguments. Accoarding to a post in a well known moderated group: "There are three possibilities for template arguments: 1)...
6
by: pauldepstein | last post by:
Let double NR( double x, double(*)(const double&) f ) be the signature of a Newton-Raphson function NR. Here, f is a function which returns a double and accepts a const double&. The aim of...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.