S
snnn
#include <iostream>
using namespace std;
int main(){
const ostream::sentry ok(cout);
if(ok) return 0;
else return -1;
}
The codes above can work well under VC++2003,but not gcc!
When I try to use gcc to compile it ,the error I get
main.cpp: In function `int main()':
main.cpp:37: error: passing `const std::basic_ostream<char,
std::char_traits<char> >::sentry' as `this' argument of `
std::basic_ostream<_CharT, _Traits>::sentry:perator bool() [with _CharT =
char, _Traits = std::char_traits<char>]' discards qualifiers
Who can tell me why?
using namespace std;
int main(){
const ostream::sentry ok(cout);
if(ok) return 0;
else return -1;
}
The codes above can work well under VC++2003,but not gcc!
When I try to use gcc to compile it ,the error I get
main.cpp: In function `int main()':
main.cpp:37: error: passing `const std::basic_ostream<char,
std::char_traits<char> >::sentry' as `this' argument of `
std::basic_ostream<_CharT, _Traits>::sentry:perator bool() [with _CharT =
char, _Traits = std::char_traits<char>]' discards qualifiers
Who can tell me why?