Let's say that I designed a class like this :
// MyClass.h
#pragma once
class MyClass
{
public:
const int member = 1; // Since it is a const-integral type var...
static const int s_member;
...
};
then I can access each member like this :
// MyClass.cpp
const int MyClass::s_member = 2; // Initialization of a static member
int main()
{
MyClass* myClass = new MyClass;
std::cout << "access to an ordinary member : " << myClass->member << " OR " << (*myClass).member << std::endl;
std::cout << "access to a static member : " << MyClass::s_member << std::endl;
...
return 0;
}
(From what I know, accessing class members by pointer only makes a slight difference: passing an address and dereferencing it.)
Here, what I'm curious about is the difference between this and the way the compiler accesses static members.
I already know that the memory for a static member is located somewhere outside the class instance, rather than inside it. (So every class instances use the same memory for their static members.)
Then, the only difference for accessing static one is "where to access"? Or there exists something beyond it?