Staitc member has to defined in a sourcefile(.cpp) because it will cause error due to duplicate definitions since headerfile(.h) is shared with many sourcefiles. However, if i type '#pragma once at the beginning of the heaerfile (or use #ifndef, #endif). it will only run the headerfile once. Then why we still need to initialize static member in a sourcefile?
// This is string1.h
#pragma once
#include <cstring> // string.h for some
using std::ostream;
using std::istream;
static int num_strings=1; //why this still gives multiple definiton error even with #proagma once at top?
class String
{
private:
static int num_strings; // number of objects
}