Can a static member of a class as the same type as the class it is member of in C?

It is perfectly legal, but the following is better: class foo: { public: static const& foo Invalidfoo() { static foo Invalidfoo_; return Invalidfoo_; } private: foo(); } This way you are guaranteed that the object is initialized the first time it is used Edit: But no matter how you do it, you still have a global object, and that can be a cause of problem. The best solution may be to call the default constructor each time you need a default constructed object. In terms of efficiency, the difference is probably negligable.

It is perfectly legal, but the following is better: class foo: { public: static const& foo Invalidfoo() { static foo Invalidfoo_; return Invalidfoo_; } private: foo(); }; This way you are guaranteed that the object is initialized the first time it is used. Edit: But no matter how you do it, you still have a global object, and that can be a cause of problem. The best solution may be to call the default constructor each time you need a default constructed object.In terms of efficiency, the difference is probably negligable.

It's legal. It's actually widely used in the singleton pattern Singletons multi threading access and creation problems. A nice article about this: C++ and the Perils of Double-Checked Locking.

It is just acting like a global variable or singleton. It's prone to the problems relating to those.

It's legal. Terrible code from a practical/style point of view, but it is legal, and technically, it can be made to work. Better than Singleton because it's immutable.

That is perfectly valid code. It doesn't have any reason to cause any problem, because static data members don't contribute to the size of the class. No matter how many static data members you define in a class, it doesn't change its size by even one byte!

Struct A { int i; char c; }; struct B { int i; char c; static A a; static B b; }; In above code, sizeof(A) == sizeof(B) will always be true. See this demo: ideone.com/nsiNL Its supported by the section $9.4.2/1 from the C++ Standard (2003), A static data member is not part of the subobjects of a class. There is only one copy of a static data member shared by all the objects of the class.

You cannot define non-static data member of the enclosing class type, because non-static members are parts of the object, and so they do contribute to the size of the class. It causes problem when calculating the size of the class, due to recursive nature of the data members. See this topic: How do static member variables affect object size?

This is actually how a singleton is implemented, except your static member would be a pointer. So yes, you're safe.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions