Friend and overloading

Hi,

I got the assignment as following questions.

1. What is difference in overloading a operator with friend and without friend function??

2. thread safe singleton.
3. in singleton if desterctor is made private then what is the way to delete the object?

thanks
closed account (zb0S216C)
1) Overloading an operator, without declaring it as a friend, is still considered a member of the class in which it is defined. "Friends" are not members of the class in which they are defined, but they do allow the friend class or function to access private and protected members of the class as if it were a member of the class.

http://www.cplusplus.com/doc/tutorial/inheritance/#friend

2) What about them?
3) http://en.wikipedia.org/wiki/Singleton_pattern

Wazzak
Last edited on
@Framework the Wikipedia link does not hold the answer, and now I am interested in knowing the answer :D
closed account (zb0S216C)
The whole idea behind singletons is that only 1 instance of a resource exists. The only way to ensure that only 1 instance of a resource exists is to declare the resource static, so that all instances refer to the same object.

Since the destructor is not an option (why, I don't know), the only possible ways are member functions, operators, or static functions. Common sense, really. I haven't given this topic much thought, so I might be missing the point here.

Wazzak
Last edited on
But my doubt is of making a singleton class that is of thread safe.
closed account (zb0S216C)
Use a std::mutex (C++11).

Wazzak
Topic archived. No new replies allowed.