You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an access error when trying to initialize a static class field with a private constructor of the same class (classical singleton pattern). I had the exact same problem at the exact same location when compiling with Visual Studio 6. I am not exactly using that compiler every day, so I never really cared about it. Now I have the same error with Watcom, which makes me wonder if I may be trespassing on some specification I don't know about. However, I made some searches and ended up only on (very old) posts from people having the problem with Visual Studio 6.
Constructors and destructor are private to avoid "accidents". Changing their access to public solves the problem, but exposes to possible buggy code that would try to create or destroy what is supposed to be a singleton. I also tried to add the static keyword on front of the line, with no change. As it is, it compiles fine with all compilers I know (gcc, clang, RECENT versions of Visual Studio, etc; all spanning many versions).
However, Watcom gives me this error:
test.cpp(14): Error! E148: col(34) access to private member 'Singleton::Singleton' is not allowed
Additionally, it looks like I can somewhat get away with it by not using the default constructor, and writing:
const Singleton Singleton::UNIQUE=1;
const Singleton Singleton::UNIQUE(1); // same behavior with this variant
Giving this error:
test.cpp(14): Error! E148: col(36) access to private member 'Singleton::~Singleton' is not allowed
This time the (non-default) constructor seems to be accessible, but not the destructor.
The text was updated successfully, but these errors were encountered:
Hello,
I have an access error when trying to initialize a static class field with a private constructor of the same class (classical singleton pattern). I had the exact same problem at the exact same location when compiling with Visual Studio 6. I am not exactly using that compiler every day, so I never really cared about it. Now I have the same error with Watcom, which makes me wonder if I may be trespassing on some specification I don't know about. However, I made some searches and ended up only on (very old) posts from people having the problem with Visual Studio 6.
So here is the code:
Constructors and destructor are private to avoid "accidents". Changing their access to public solves the problem, but exposes to possible buggy code that would try to create or destroy what is supposed to be a singleton. I also tried to add the static keyword on front of the line, with no change. As it is, it compiles fine with all compilers I know (gcc, clang, RECENT versions of Visual Studio, etc; all spanning many versions).
However, Watcom gives me this error:
test.cpp(14): Error! E148: col(34) access to private member 'Singleton::Singleton' is not allowed
Additionally, it looks like I can somewhat get away with it by not using the default constructor, and writing:
const Singleton Singleton::UNIQUE=1;
const Singleton Singleton::UNIQUE(1); // same behavior with this variant
Giving this error:
test.cpp(14): Error! E148: col(36) access to private member 'Singleton::~Singleton' is not allowed
This time the (non-default) constructor seems to be accessible, but not the destructor.
The text was updated successfully, but these errors were encountered: