Reputation:
In item 4 (page 30/31 in Effective C++ 3rd Ed. ) the following Code example is provided:
Translation Unit 1:
class FileSystem {
public:
...
std::size_t numDisks() const;
...
};
extern FileSystem tfs;
Translation Unit 2:
class Directory {
public:
Directory( params );
...
};
Directory::Directory( params )
{
...
std::size_t disks = tfs.numDisks();
...
}
Directory tempDir( params );
Now Meyers refers to tempDir
as static object. (page 31, 2nd paragraph)
But
tfs
andtempDir
were created by different people at different times in different source files — they’re non-local static objects defined in different translation units.
Well obviously tfs
is static because it was declared with extern, but why the hack should tempDir
be static?
Upvotes: 0
Views: 122
Reputation: 92381
static
has (too) many meanings in C++. Here it means that tempDir
is defined in the static data area, outside of any functions.
It is not dynamically allocated and it is not a local automatic storage variable.
Upvotes: 4