g++ does not show a 'unused' warning

后端 未结 3 1801
一个人的身影
一个人的身影 2020-11-29 11:13

I have a little piece of code in C++:

#include 
#include 
#include 

using namespace std;

int main() {

    in         


        
3条回答
  •  情歌与酒
    2020-11-29 11:36

    istream_iterator has a constructor, so the declaration of EOS isn't really a no-op like the declarations of i and x are.

    Often you want to declare a class-type object and then not do anything with it. For example, consider std::lock_guard in C++0x (boost::scoped_lock in Boost) or any other kind of scope guard class. You don't usually want to do anything with that kind of object, you just want to create the object so that its destructor get run at the end of the block to perform whatever cleanup needs to be performed.

提交回复
热议问题