I have implemented a Meyer's singleton pattern. And I try to do some stuff testing it in a multithreading environment. Here is how I implemented the class in C++.  #include&lt;thread&gt; #include&lt;mutex&gt; class singleton { public:   static singleton&amp; instance() {     std::lock_guard&lt;std::mutex&gt; lck(mtx);     static singleton *my = new singleton;     return *my;   } private:   static std::mutex mtx;   singleton() {}   ~singleton() {}   singleton(const singleton &amp;) {}   singleton&amp; operator=(const singleton &amp;) {} };   But when I compile this with g++ -std=c++11 singleton.cpp -o singleton -lpthread, it says   /tmp/ccfEBnmN.o: In function `singleton::instance()': singleton.cpp(.text._ZN11singleton12instanceEv[_ZN11singelton12instanceEv]+0x10): undefined reference to `singleton::mtx' collect2: error: ld returned 1 exit status   I understand this might be some problem in design, since without initializing the first singleton instance how could we get the mtx. If in this case, my question comes to how to implement a thread safe singleton class based on my code? How do we initialized the mtx in my singleton class?  I know there is a traditional way to create a singleton pattern by maintaining a static pointer points to the singleton class. But indeed that is not "so" thread safe. Even applying the double check mechanism in the instance() method.
Can anyone explain why following code won't compile? At least on g++ 4.2.4.  And more interesting, why it will compile when I cast MEMBER to int?  #include &lt;vector&gt;  class Foo {   public:       static const int MEMBER = 1;   };  int main(){       vector&lt;int&gt; v;       v.push_back( Foo::MEMBER );       // undefined reference to `Foo::MEMBER'     v.push_back( (int) Foo::MEMBER ); // OK       return 0; }
Many older movies seem to have vivid reds and particularly realistic or noticeable skin tones (they certainly seem to stand out from typical skin tones on TV or the majority of movies). This applies even in DVD or online versions and is not, given the range of material I've noticed the effect in, an artifact of special post processing or deliberate colour manipulation.  All the movies I've noticed the effect in are from the film era, especially from when colour became common to the late 1960's. I used to think it was just Technicolor but I've seen things recently that don't claim to be Technicolor that also show the effect.   claims the effect was due to the final print being constructed late in the process for separate black and white film strips for each primary colour allowing the final dyes to be very vivid and clear:     The rich colors that the Technicolor process gave came in part from the fact that the color was not added to the process until the final stages. The color information was recorded and processed as separate black and white images which were relatively easy to control and preserve.   Is this a good explanation? When I loaded the review page (in Stack Overflow, though I have no specific reason to think it is related) I got a weird hat in the upper left hand corner.    See the hat in the upper left hand corner?  That's belonging to user # .  His profile page also has the hat in a ... weird ... location, but not this weird.    I'm guessing this is due to the not-loaded image for the avatar (adblock blocks Facebook avatars for me often)?  It also causes the toolbar notification to show his link unless I'm hovering over something else.  It also changes the location of the gray box to the upper left hand corner when I hover over the hat (and hovering over the white box does nothing).  It's definitely him (or any not-loaded avatar perhaps), once he fell off the last 6 reviewers it stopped appearing. I'm planning to attend a Californian university as a visiting scholar (not paid by the university) on a J-1 visa, for a total of four weeks; a colleague of mine will do the same, but for 12 weeks. I've been told (personally, ie. no citable sources) that, if you're staying on a J-1, you're effectively a California resident for the time you're there, and, therefore, need a Californian driver's license.  I've read up on this and found  that states:     If you are a visitor in California over 18 and have a valid driver   license from your home state or country, you may drive in this state   without getting a California driver license as long as your home state   license remains valid.      If you become a California resident, you must get a California driver   license within 10 days. Residency is established by voting in a   California election, paying resident tuition, filing for a homeowner's   property tax exemption, or any other privilege or benefit not   ordinarily extended to nonresidents.   I'm not planning to vote in any elections, nor will I own a home there, but I'm not sure what would constitute "privileges or benefits not ordinarily extended to nonresidents".  Do we need to get driver's licenses in California, or can we use our foreign licenses? How about day trips to Arizona or Nevada?  Note: this seems to be related to , but my question is specifically about staying there on a J-1. Unzip File: Permission Denied I am trying to unzip a file (Facebook download-your-info zip file), but here's what I got:   Is there a way I can force-unzip it?  Update: I tried sudo unzip file.zip -d destination_folder in terminal, and it unzipped the file, but what came out, all the files have size 0 bytes:   Update 2: I do have permission to the directory and the file.    (I'm really sorry if my question is asked badly. Let me know down in the comments :) ) Convergent or divergent series: $\sum_{n=1}^{\infty} \sqrt{a_n \cdot a_{n+1}}$? suppose that $\sum_{n=1}^{\infty}a_n$ is a convergent series of positive terms. Prove that $\sum_{n=1}^{\infty} \sqrt{a_n \cdot a_{n+1}}$ is also convergent. Demonstrate that the converse is false. What makes a bread either close or open crumbed/textured? What causes the texture of bread to be open, ie with lots of large holes, or close, ie a regular, uniform tender crumb with no large holes? How can I achieve either? jQuery - multiple $(document).ready ...? Profile page "activity" tab is broken I am running k-fold cross validation on my training data, and then choosing the best set of hyper parameters, re-training on the training data and testing on a new (unseen) testing data. I am getting the following testing results (results on the unseen data):  R^2: 1.000 Adj R^2: 1.000 RMSE: 0.081 MSE: 0.007 MAE: 0.045 MAPE: 0.058   Can $R^2$ have a value of 1.00 but RMSE have a  value of 0.081? Doesn't an $R^2$ of value 1 indicate no errors at all? Help center still has the guidance about old Favorite tags An explanation for the Landauer's principle Has anyone understood the ? What is the current status?  In specific, is there a theoretical derivation of the Landauer's Principle?(not the heuristic one based on Salizard's engine) How does one account for thermodynamic concepts applicable to situations involving measurement? What does it mean to reset the state of the apparatus why is free energy expended in the process? Number of solutions to the congruence $x^q \equiv 1 \mod p$. Let $p, q$ be distinct odd primes, I would like to compute the number of solution $\mod p$ to the congruence $x^q \equiv 1 \mod p$. (Show that it's $gcd(q, p - 1))$  If $x^q \equiv 1 \mod p$, since $q$ is prime, this must mean that $x$ is either $1$ or has order $q$.   Hence, the problem reduces to finding the number of elements of $U_p$ which is either $1$ or has order $q$.  If $ q \nmid  p - 1$, then there is only one element, namely $1$.  If $q \mid p - 1$, then the number of elements of order $q$ is $\phi(q) = q - 1$, and so the number of solutions to the congruence $\mod p$ is $q - 1 + 1 = q$, and in either case the number of solutions is $\gcd(q, p - 1)$.  Does this look fine? "The only thing necessary for the triumph of evil is for good men to do nothing." -Edmund Burke  Is there an idiom, phrase or preferably a single word that we can call people that could have helped but didn't? Bystanders don't necessarily have help to give. Cowards aren't particularly helpful either.    Addendum:  For example, once EMS has arrived on scene, bystanders are encouraged not to try to help, unless they're a nurse and therefore have the necessary skills to, and sometimes even then so. If in The Service, I would not want a coward (a liability) next me holding the line. Not to take anything away from these great answers, or to insist on a non-militaristic point of view, I would like to veer into the commercial or civilian realm in which I find this quote most often alluded to, E.G., "If we all gave 5 cents we could cure cancer tomorrow." Pretend most of us did give 5 cents and we did cure cancer, but you didn't give. You are now a(n) ____?... yes, I know what we call them, but what is their proper designation? Assessing approximate distribution of data based on a histogram Suppose I want to see whether my data is exponential based on a histogram (i.e. skewed to the right).   Depending on how I group or bin the data, I can get wildly different histograms.   One set of histograms will make is seem that the data is exponential. Another set will make it seem that data are not exponential. How do I make determining distributions from histograms well defined? How do you make numbered equations in latex? I would like to put in a code that automatically assigns a number to the equations in my documents preferably aligned on the right hand side.   How can I go about this?   \documentclass[a4paper,11pt]{article} %\documentclass[a4paper,11pt]{scrartcl} \usepackage{amsmath}  \usepackage[utf8]{inputenc}  \begin{document}  $$\ddot{\underline{\mathbf{r}}} = \frac{d{^2}\underline{\mathbf{r}}}{dt^2}= 0$$.  \end{document} Why is Severus Snape's Patronus the same as Lily Potter's? Are Snape and Lily related somehow? Are Snape and Harry related? Is there any text editor which supports Markdown (Ask Ubuntu's formatting style)? When may adjectives precede determiners? (E.g. too difficult a task) The expression too difficult a task sounds a little pompous, but it doesn't sound ungrammatical. According to my folk-beliefs about English grammar, determiners precede adjectives. However, the expression too difficult a task seems to controvert that belief.  Additionally, the expression too difficult of a task seems grammatical too.    Under what conditions may determiners precede adjectives? Are there conditions under which too difficult of a task would be a more grammatical expression than too difficult a task would be?   (This question does not ask what the question “How big of a problem” vs. “how big a problem” asks. That question does not pertain to determiners.) Order of redirections I don't quite understand how the computer reads this command.  cat file1 file2 1&gt; file.txt 2&gt;&amp;1  If I understand, 2&gt;&amp;1 simply redirect Standard Error to Standard Output.  By that logic, the command reads to me as follows:    concatenate files file1 and file2.  send stdout from this operation to file.txt. send stderr to stdout. end?   I'm not sure what the computer's doing. By my logic, the command should be   cat file1 file2 2&gt;&amp;1 &gt; file.txt   but this is not correct. How do I add a .sty file to my MacTeX/TeXShop installation?