c++ - static initialization confusion -


I am getting very confused in some concepts in C ++: for pre: I have followed two files

  // file1.cpp class test {static int s; Public: test () {s ++;}}; Static test t; Int test :: s = 5; //file2.cpp # include & lt; Iostream & gt; using namespace std; Class test {static int s; Public: test () {s ++;} static int mill () {returns s; }}; Static test t; Int main () {cout & lt; & Lt; Test :: get () & lt; & Lt; Endl; }  

Now my question is this: 1. 1. How to successfully complete two files even if they have different definitions of different classes?
2. Are the stable members of the two classes because I get the output as 7.

Please tell this concept of statics.

They link because the linker knows almost nothing about the C ++ language though, if If you do this, you have broken a definition rule, and your program's behavior will be undefined. Writing invalid code is not a good way to learn C ++ Also, you start to have a lot of questions about the stable variable - the concept is not really complicated - that's the C ++ textbook that you are using Does not explain well?


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -