468,456 Members | 1,806 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,456 developers. It's quick & easy.

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 953
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Andy Fish | last post: by
2 posts views Thread by littlefitzer | last post: by
7 posts views Thread by Hendrik Schober | last post: by
7 posts views Thread by Lionel B | last post: by
7 posts views Thread by StephQ | last post: by
6 posts views Thread by pauldepstein | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.