Home > OS >  In headers, should variables be declared as "extern" even if they are class data members?
In headers, should variables be declared as "extern" even if they are class data members?

Time:02-05

I read in other posts that header variables should be declared using "extern" to prevent multiple definitions / memory allocation if the header is imported into several .cpp files.

Is it also the case when these variables are class data members? I think not because including the class header don't create instances, so I don't see why a memory allocation would occur, but I'm not sure.

CodePudding user response:

The answer is no. To do so generates a compiler error.

  •  Tags:  
  • Related