T
Thomas Lenz
The code below should allow to use a comma instead of << with ostreams and
include a space between two operands when comma is used. e.g.
cout << "hello", "world", endl;
should print the line "hello world".
#include <iostream>
using namespace std;
inline std:stream& operator,(std:stream& rhs_, std:stream& (* arg_
(std:stream&))
{ return (rhs_ << arg_);
}
template<class T> std:stream& operator,(std:stream& rhs_, T arg_) {
return (rhs_ << ' ' << arg_); }
int main()
{ cout << "hello", "world", endl;
}
When I compile with the Weffc++ option, i get the warnings:
junk.cpp:5: Warning: user-defined »std:stream& operator,(std:stream&,
std:stream& (*)(std:stream&))« always evaluates both arguments
junk.cpp:9: Warning: user-defined »std:stream& operator,(std:stream&,
T)« always evaluates both arguments
Why? I mean, of course the operator evaluates both arguments, that's what
they are for. BTW the code works fine; I'm just confused by these warnings.
I didn't find anything in the effective c++ books that could throw some
light on this. Can you?
Thanks,
Thomas
include a space between two operands when comma is used. e.g.
cout << "hello", "world", endl;
should print the line "hello world".
#include <iostream>
using namespace std;
inline std:stream& operator,(std:stream& rhs_, std:stream& (* arg_
(std:stream&))
{ return (rhs_ << arg_);
}
template<class T> std:stream& operator,(std:stream& rhs_, T arg_) {
return (rhs_ << ' ' << arg_); }
int main()
{ cout << "hello", "world", endl;
}
When I compile with the Weffc++ option, i get the warnings:
junk.cpp:5: Warning: user-defined »std:stream& operator,(std:stream&,
std:stream& (*)(std:stream&))« always evaluates both arguments
junk.cpp:9: Warning: user-defined »std:stream& operator,(std:stream&,
T)« always evaluates both arguments
Why? I mean, of course the operator evaluates both arguments, that's what
they are for. BTW the code works fine; I'm just confused by these warnings.
I didn't find anything in the effective c++ books that could throw some
light on this. Can you?
Thanks,
Thomas