Hi!
First, thanks to "Giovanni Bajo" <[EMAIL PROTECTED]> for help.
Consider simple C++ program:
-----------------------------------------
#include <map>
template<class _K, class _V>
void func_map(typename std::map<_K, _V>::iterator& root) {
}
int main() {
std::map<int, int> mymap;
func_map<int, int>(mymap.begin());
}
-----------------------------------------
Notice '&' in the line:
void func_map(typename std::map<_K, _V>::iterator& root) {
Just because this '&' program won't compile:
(gcc 3.4.1 log):
------------------------------------------
testref.cpp: In function `int main()':
testref.cpp:18: error: invalid initialization of non-const reference of type
'std::_Rb_tree_iterator<std::pair<const int, int> >&' from a temporary of
type 'std::_Rb_tree_iterator<std::pair<const int, int> >'
testref.cpp:9: error: in passing argument 1 of `void func_map(typename
std::map<_K, _V, std::less<_Key>, std::allocator<std::pair<const _Key, _Tp> >
>::iterator&) [with _K = int, _V = int]'
-------------------------------------------
Why does std::_Rb_tree_iterator<std::pair<const int, int> >& appear?
Just remove '&' from typename std::map<_K, _V>::iterator& root
- no warnings, no errors.
Is it gcc bug or ISO C++ violation?
Also, much more simple example won't work:
----------------------------------------------
void func(const char *& p) { // Another developer puts '&' here.
}
int main() {
char *ptr = "dsadas";
// I can't write 'const char *' because of program's mutable logic.
// This logic intoduced by another developer.
func(ptr);
}
-----------------------------------------------
And, just remove '&' and all is ok.
NOTE. MSVC6 compiles all code above.