2007年2月26日星期一

Ways to introduce a new name into a file in CPP

Here they are:



  1. using "#include " to include all names defined in the included file (mostly are headers)

  2. using "extern" to introduce names (of variables and functions) with external linkage
  3. using "class x" to do a forward declaration
  4. using "typedef x y" to introduce type names, due to ODR (one definition rule), it won't cause duplicate definitions
  5. using "template <typename T> class t; typedef t<x> y;" to introduce a specification of a template into the header, due to two-phase parsing and POI (point of instantiation), this will also not cause a duplicate definitions
Maybe there are other ways that I don't know for introducing names into header, if you know some, I'm glad to hear about that:)











Technorati Tags:







powered by performancing firefox