How does extern work in c++?

后端 未结 5 1920
温柔的废话
温柔的废话 2021-01-12 10:03

This is from the :

namespace std 
{
  extern istream cin;       ///< Linked to standard input
  extern ostream cout;  
...
         


        
5条回答
  •  一生所求
    2021-01-12 10:50

    extern is used to refer to a variable defined in a different compilation unit (for now, you can think of a compilation unit as a .cpp file). The statements in your example declare rather than define cin and cout. It is telling the compiler that the definition of these objects is found in another compilation unit (where they are not declared as extern).

提交回复
热议问题