The declaration and definition of data

it2024-03-23  58

Distinguish among “int”, “double”, “const int”, “const double”, “static int”, “static double”, “static const int”, and “const static double”.

“h.hpp” file namespace flow3 { class f1 { public: f1(); int a; double b; const int c; const double d; static int e; static double f; static const int g; // also can be defined as "static const int g = 7;". const static double h; }; extern f1 fw; } “h.cpp” file #include "h3.h" namespace flow3 { const int f1::g = 7; const double f1::h = 8.0; int f1::e = 5; double f1::f = 6.0; f1::f1():c(3), d(4.0) { a = 1; b = 2.0; } f1 fw; } “test.cpp” file which includes main program int main() { using namespace flow3; cout << fw.a << endl; cout << fw.b << endl; cout << fw.c << endl; cout << fw.d << endl; cout << fw.e << endl; cout << fw.f << endl; cout << fw.g << endl; cout << fw.h << endl; return 0; }
最新回复(0)