So I have this problem for a while now. I just couldn't find the answer to the question. Why do I have to give the data type twice while using static variables inside a class?
Here's an example:
#include <iostream>
class Test{
public:
static int test;
};
//right here is the point of confusion
int Test::test = 10;
int main(){
Test test;
std::cout << test.test << "\n";
}
As you can see from my program above I had to initialize the variable this way. But what about the duplicate data type specification? Why did I have to write the "int" data type twice? Once already in the class and then again? What is the underlying reason? Thanks for any help in advance.