G
Guenther Brunthaler
Hi template specialists,
I have a problem with the code listed below.
What I wanted to do is defining an operator<< that is able to output
a 'matrix<ELEMENT_T, INDEX_T>::subrange' object
into a 'std::basic_ostream<charT, traits>'.
For some reason, it does not work. The compiler always complains:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
te.cpp:
Error E2094 test.cpp: 'operator<<' not implemented in type
'std:stream' for arguments of type 'matrix<double,unsigned
int>::subrange' in function main(int,char * *)
*** 1 errors in Compile ***
The INTEL compiler gives a similar error.
On the other hand, MSVC 7 compiles without any warnings.
So - which of the compilers are correct?
And does anyone have an idea what there might be wrong with the code?
Note:
If I change the code to output a
'matrix<ELEMENT_T, INDEX_T>'
instead of a
'matrix<ELEMENT_T, INDEX_T>::subrange'
then it works perfectly for all compilers!
Only that this is not what I actually want to do.
So, please help me if you possibly can!
---------snip-----------
#include <iostream>
#include <cstdlib>
template<typename ELEMENT_T, typename INDEX_T>
struct matrix {
// I want to output an object of this nested type.
struct subrange {};
};
// This templated global function will not be used
// due to some reason unknown to me.
template<
typename ELEMENT_T, typename INDEX_T, typename charT, typename traitsstd::basic_ostream<charT, traits> &operator<<(
std::basic_ostream<charT, traits> &os,
matrix<ELEMENT_T, INDEX_T>::subrange const &range)
{
os <<"matrix range";
return os;
}
int main(int, char **) {
matrix<double, size_t>::subrange x;
std::cout << x;
return EXIT_SUCCESS;
}
---------snip-----------
sincerly,
Guenther
I have a problem with the code listed below.
What I wanted to do is defining an operator<< that is able to output
a 'matrix<ELEMENT_T, INDEX_T>::subrange' object
into a 'std::basic_ostream<charT, traits>'.
For some reason, it does not work. The compiler always complains:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
te.cpp:
Error E2094 test.cpp: 'operator<<' not implemented in type
'std:stream' for arguments of type 'matrix<double,unsigned
int>::subrange' in function main(int,char * *)
*** 1 errors in Compile ***
The INTEL compiler gives a similar error.
On the other hand, MSVC 7 compiles without any warnings.
So - which of the compilers are correct?
And does anyone have an idea what there might be wrong with the code?
Note:
If I change the code to output a
'matrix<ELEMENT_T, INDEX_T>'
instead of a
'matrix<ELEMENT_T, INDEX_T>::subrange'
then it works perfectly for all compilers!
Only that this is not what I actually want to do.
So, please help me if you possibly can!
---------snip-----------
#include <iostream>
#include <cstdlib>
template<typename ELEMENT_T, typename INDEX_T>
struct matrix {
// I want to output an object of this nested type.
struct subrange {};
};
// This templated global function will not be used
// due to some reason unknown to me.
template<
typename ELEMENT_T, typename INDEX_T, typename charT, typename traitsstd::basic_ostream<charT, traits> &operator<<(
std::basic_ostream<charT, traits> &os,
matrix<ELEMENT_T, INDEX_T>::subrange const &range)
{
os <<"matrix range";
return os;
}
int main(int, char **) {
matrix<double, size_t>::subrange x;
std::cout << x;
return EXIT_SUCCESS;
}
---------snip-----------
sincerly,
Guenther