I tried to implement a singleton class in the following way (I use VS2008 SP1) :
namespace firstNamespace
{
class SingletonClass
{
private SingletonClass() {}
public static readonly SingletonClass Instance = new SingletonClass();
}
}
When I want to access it from a class in a different namespace (it seems that this is the problem, in the same namespace it works) like :
namespace secondNamespace
{
...
firstNamespace.SingletonClass inst = firstNamespace.SingletonClass.Instance;
...
}
I get a compiler error:
error CS0122: 'firstNamespace.SingletonClass' is inaccessible due to its protection level
Does somebody have an idea how to solve this?
Many thanks in advance!
Singleton in C++ Singleton is a creational design pattern, which ensures that only one object of its kind exists and provides a single point of access to it for any other code. Singleton has almost the same pros and cons as global variables.
Example of singleton classes is Runtime class, Action Servlet, Service Locator. Private constructors and factory methods are also an example of the singleton class.
Singleton pattern is used for logging, drivers objects, caching, and thread pool. Singleton design pattern is also used in other design patterns like Abstract Factory, Builder, Prototype, Facade, etc. Singleton design pattern is used in core Java classes also (for example, java. lang.
singleton (plural singletons) (playing cards) A playing card that is the only one of its suit in a hand, especially at bridge. (playing cards) A hand containing only one card of a certain suit.
You're missing the keyword public
from your class definition.
Sounds more like the singleton is in a different assembly. The default modifier for a class is internal and thereby only accessible in the assembly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With