By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

Problem of template

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.