G
Guest
I'm using a user-defined diagnostics stream and custom manipulators that work with it
template<class charT, class traits = std::char_traits<charT>
class basic_diagsstream : public std::basic_ostream<charT, traits
...
}
and a manipulator
class alar
template <typename charT, typename traits
friend basic_diagsstream<charT, traits>& operator <
(basic_diagsstream<charT, traits>& os, const alarm& a
// manipulate the diagnostics strea
..
return os
}
Intentionally, I defined the put operator inside the alarm manipulator, paying tribute to Angelika and Klaus for the boilerplate code, and to Nicolai and David for the Barton-Nackman explanation :-
I had been using code like this
// Works in VC
diags << "Hello, world"
diags << alarm(STOP_THE_WORLD_I_WANT_TO_GET_OFF)
diags << "Stop!" << alarm(I_WANT_TO_GET_OFF_TOO)
where diags is an instance of basic_diagstream
However, when porting to VC7.1, this code breaks. To fix it, I had to
- Bring the friend function definition for the put operator outside of the alarm manipulator
- Change the signature to take a basic_ostream instead
- Cast inside the global put operator
class alar
template <typename charT, typename traits
friend std::basic_osstream<charT, traits>& operator <
(std::basic_osstream<charT, traits>& os, const alarm& a)
}
template <typename charT, typename traits
std::basic_osstream<charT, traits>& operator <
(std::basic_osstream<charT, traits>& os, const alarm& a
// cast then manipulate..
dynamic_cast<basic_diagstream<charT, traits>>(os)
..
return os
Since VC7.1 is more compliant than VC7, I have the following questions (from the perspective of using VC7.1)
In VC7.1, when defining the put operator within the manipulator (alarm), the code does not compile. The compiler barfs that there is no suitable operator taking an alarm in the rhs. My assumption is that it had to do with Koenig Lookup finding the operator<< that takes an ostream, but could not find an overload that takes an alarm manipulator on its rhs. I would have expected it to find the operator defined inside the alarm manipulator, but it didn't, obviously
- Why does it work in VC7 and not in VC7.1? Does the friend name injection limit the name exposure of the operator<< inside the alarm manipulator (and this limitation is obviously applicable to VC7.1 only)
Regards
Javier Estrad
template<class charT, class traits = std::char_traits<charT>
class basic_diagsstream : public std::basic_ostream<charT, traits
...
}
and a manipulator
class alar
template <typename charT, typename traits
friend basic_diagsstream<charT, traits>& operator <
(basic_diagsstream<charT, traits>& os, const alarm& a
// manipulate the diagnostics strea
..
return os
}
Intentionally, I defined the put operator inside the alarm manipulator, paying tribute to Angelika and Klaus for the boilerplate code, and to Nicolai and David for the Barton-Nackman explanation :-
I had been using code like this
// Works in VC
diags << "Hello, world"
diags << alarm(STOP_THE_WORLD_I_WANT_TO_GET_OFF)
diags << "Stop!" << alarm(I_WANT_TO_GET_OFF_TOO)
where diags is an instance of basic_diagstream
However, when porting to VC7.1, this code breaks. To fix it, I had to
- Bring the friend function definition for the put operator outside of the alarm manipulator
- Change the signature to take a basic_ostream instead
- Cast inside the global put operator
class alar
template <typename charT, typename traits
friend std::basic_osstream<charT, traits>& operator <
(std::basic_osstream<charT, traits>& os, const alarm& a)
}
template <typename charT, typename traits
std::basic_osstream<charT, traits>& operator <
(std::basic_osstream<charT, traits>& os, const alarm& a
// cast then manipulate..
dynamic_cast<basic_diagstream<charT, traits>>(os)
..
return os
Since VC7.1 is more compliant than VC7, I have the following questions (from the perspective of using VC7.1)
In VC7.1, when defining the put operator within the manipulator (alarm), the code does not compile. The compiler barfs that there is no suitable operator taking an alarm in the rhs. My assumption is that it had to do with Koenig Lookup finding the operator<< that takes an ostream, but could not find an overload that takes an alarm manipulator on its rhs. I would have expected it to find the operator defined inside the alarm manipulator, but it didn't, obviously
- Why does it work in VC7 and not in VC7.1? Does the friend name injection limit the name exposure of the operator<< inside the alarm manipulator (and this limitation is obviously applicable to VC7.1 only)
Regards
Javier Estrad