Bjarne's member function binding sample is wrong?

Joined
Feb 12, 2008
Messages
108
Reaction score
0
Hello everyone,


Here is the quoted section, words from Bjarne and his sample. The reason why I think the sample is wrong, is because, the member function sort accepts empty arguments, so when we call ::sort (v), only the one in global namespace will be matched -- there is no ambiguity to call sort member function of Container from parameter list comparison. I do not know why Bjarne commets "sort (vector<T>&) which calls std::sort() rather than Container::sort()" -- I think it has nothing to do with template -- just a normal function call matching.

Any comments? Do you agree with me and think his sample is wrong?

section 13.8.3 Point of Instantiation Binding

--------------------
unqualified name can not be bound to members of that class
--------------------

Code:
template <class T> void sort (vector<T>& v)
{
	sort (v.begin(), v.end());
}

class Container {
	vector<int> v; // elements
public:
	void sort() // sort elements
	{
		::sort (v); // sort (vector<T>&) which calls std::sort() rather than Container::sort()
	}
};


thanks in advance,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,264
Messages
2,571,065
Members
48,770
Latest member
ElysaD

Latest Threads

Top