failed compilation when #include .h file but succeeded when #include .cpp file failed to compile C++ when using #include .h file  I have 3 files: linkedStack.cpp linkedStack.h and main.cpp.  g++ -o main linkedStack.cpp main.cpp   it failed to compile when I enter the command above,  but it worked when I changed #include "linkedStack.h" into #include "linkedStack.cpp". I wonder why?  The linkedStack.h file is as follows:  #include &lt;stdio.h&gt; #include &lt;iostream&gt; #include &lt;string&gt; #include &lt;assert.h&gt;  using namespace std;    template &lt;class Type&gt;  class stackADT  {  public:  virtual void push(const Type&amp; newItem)=0;//to add newItem to the stack  virtual Type top() const=0;//to return the top element of the stack    template &lt;class Type&gt; struct nodeType {     Type info;     nodeType&lt;Type&gt;*link; };  template &lt;class Type&gt; class linkedStackType//:public stackADT&lt;Type&gt; { public:       virtual  void push(const Type&amp; newItem);//add a new element      linkedStackType();//default constructor      ~linkedStackType();//destructor      virtual  Type top() const;//return the top element private:     nodeType&lt;Type&gt;*stackTop;  };   The linkedStack.cpp file is as follows:  #include "linkedStack.h"  template &lt;class Type&gt; linkedStackType&lt;Type&gt;::linkedStackType() {//default constructor     stackTop=NULL; }  template &lt;class Type&gt; Type linkedStackType&lt;Type&gt;::top() const {     assert(stackTop!=NULL);     return stackTop-&gt;info;  }//return the top element of the stack ,otherwise terminate the program if the stack is empty template &lt;class Type&gt; void linkedStackType&lt;Type&gt;::push(const Type&amp; newItem) {//add a new element     nodeType&lt;Type&gt;* newNode;     newNode =new nodeType&lt;Type&gt;;     newNode-&gt;info=newItem;     newNode-&gt;link=stackTop;     stackTop=newNode; }   The main.cpp file is as follows:  #include &lt;linkedStack.h&gt; int main() {     linkedStackType&lt;int&gt; stack;     stack.push(34);     cout&lt;&lt;stack.top()&lt;&lt;endl;     return 0; }   The result is as follows :  g++ -o main linkedStack.cpp main.cpp  Undefined symbols for architecture x86_64:   "linkedStackType&lt;int&gt;::isFullStack() const", referenced from:       vtable for linkedStackType&lt;int&gt; in main0728-bb04be.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Why can templates only be implemented in the header file? Quote from :     The only portable way of using templates at the moment is to implement them in header files by using inline functions.   Why is this?  (Clarification: header files are not the only portable solution. But they are the most convenient portable solution.)
I have a dual monitor set-up. When I'm on YouTube, and I click the fullscreen icon, the fullscreen automatically goes to the second monitor. How do I get it to go fullscreen on my main monitor? $g^k$ is a primitive element modulo $m$ iff $\gcd (k,\varphi(m))=1$ An inequality for arctan$x$ Why it is true that $|\arctan x-\arctan y|\leq |x-y|$? I have tried to use $\tan x$ but I didn't conclude to something. How to connect to device via SSH over direct ethernet connection I have a device that I need to connect to over SSH. The device is connected to my workstation via a direct ethernet connection. I'm attempting to assign the connected device an IP address somehow that I can SSH to, however all of the guides I'm finding have the user configure the IP from whatever device they're working with (namely Raspberry Pi's and so on). This is not something I can do with this device as I've no physical interface to work with.  I've been recommended to setup a DHCP server on my workstation so it would take care of this for me, however I've no idea how to configure it and none of the guides I have followed have been helpful. With that approach, I seem to have been able to bind an IP to the interface the device is connected on, however SSHing to that IP just brings me back to my own machine.  So my main question is: How do I assign an IP address to a device directly connected to my computer via ethernet cable without having any kind of access to the device (no interface, keyboard, monitor, etc). If the answer is to set up a DHCP server on my machine, how do I properly configure this and get an IP I can SSH to?  For reference, I am using Ubuntu 16.04 with OpenSSH installed. The device is also running some flavor of Linux and has SSH software installed, but again there's no way to interact with it except through SSH. I also do not have access to my router, so plugging the device in there and letting the router do the work is not an option. As a new user on a site, what's the best way to ensure your question will be positively received? Why does String.split need pipe delimiter to be escaped? Why is everybody so concerned about etc/passwd? Here is the content of my vagrant machine of this particular file:  root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/us$ nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin syslog:x:100:103::/home/syslog:/bin/false   Could anybody explain me why it is bad if some evil guy could get this file of my production server? Divisibility by 7 What is the fastest known way for testing divisibility by 7? Of course I can write the decimal expansion of a number and calculate it modulo 7, but that doesn't give a nice pattern to memorize because 3 is a primitive root. I'm looking for alternative ways that can help you decide when a number is divisible by 7 by hand.  I'm sorry if this is a duplicate question, but I didn't find anything similar on the site. Customizing tray/taskbar date display in Ubuntu with GNOME 3 Windows is unable to detect disk partitions I installed Windows 8.1 Preview using the DVD yesterday after wiping off my HDD (I made a backup prior to that). While installing Windows I created only the partitions necessary to install Windows (System Reserved, C: shown in second screenshot). Further I installed Ubuntu 13.04. During Ubuntu installation I created necessary extended partitions (for OS, swap and home directory - all ext4 except swap). Later within Ubuntu I created a NTFS partition at the end (partition 4 in first screenshot). This was a primary partition. The objective behind this was that the partition must be accessible from Windows.  While Ubuntu disk utility reports the partitioning just fine (as below)  Windows disk management is showing all partitions as primary.   Thus within Windows I am able to access only C:! What puzzles me is one can't create so many primary partitions! How can I solve this issue? I have thus far avoided the nightmare that is testing multi-threaded code since it just seems like too much of a minefield.  I'd like to ask how people have gone about testing code that relies on threads for successful execution, or just how people have gone about testing those kinds of issues that only show up when two threads interact in a given manner?  This seems like a really key problem for programmers today, it would be useful to pool our knowledge on this one imho. This is a general question that was asked indirectly multiple times in here, but it lacks a single authoritative answer. It would be great to have a detailed answer to this for the reference.  , the proportion of correct classifications among all classifications, is very simple and very "intuitive" measure, yet it may be a . Why does our intuition misguide us here and are there any other problems with this measure? How to compute PCA scores from eigendecomposition of the covariance matrix? Given a data matrix $\mathbf X$ of $12 \times 7$ size with samples in rows and variables in columns, I have calculated centered data $\mathbf X_c$ by subtracting column means, and then computed covariance matrix as $\frac{1}{N-1} \mathbf X_c^\top \mathbf X_c$.  The dimensions of this covariance matrix are $7 \times 7$. After that I have calculated the eigenvalue decomposition, obtaining eigenvector matrix $\mathbf V$ with eigenvectors in columns.  Now I want to know about projections (i.e. principal component scores in PCA): is it $\mathbf{V}^\top \mathbf{X}_c$ or $\mathbf{X}_c \mathbf{V}$?  mean_matrix = X - repmat(mean(X),size(X,1),1); covariance = (transpose(mean_matrix) * mean_matrix)/(12-1);  [V,D] = eig(covariance); [e,i] = sort(diag(D), 'descend'); V_sorted = V(:,i); A question about the idea of Laplace transform In Laplace integral transform equation one multiplies the function $f(t)$ by $e^{-st}$. I read in many tutorials that $e^{-st}$ decays much faster than any other function so the integral diverges.  But what I don't understand what makes one to think to multiply a function with  $e^{-st}$ to transform it in $s$ domain? What is the motivation behind it? Why would you suddenly come up with an idea as such: "Oh there is a function $f(t)$ in time domain what can I do to transform it to complex freq. ($s$) domain? Hmm let me multiply it with $e^{-st}$ and integrate it from zero to infinity" What would have motivated this idea of multiplying and integrating for transformation? JSON encode MySQL results How do I use the json_encode() function with MySQL query results? Do I need to iterate through the rows or can I just apply it to the entire results object? Can I delete unnecessary device simulators of Xcode? I found that Xcode on my laptop consumes much of its storage, so I am trying to delete unnecessary files in Xcode.  There are four directories under Application/Xcode.app/Contents/Developer/Platforms/. I feel that WatchSimulator.platform and AppleTVSimulator.platform are not necessary, because I use Xcode almost only for basic iOS development.  I would like to know if I can delete those platforms directories directly? Why the name 'Rogue One'? So far, is there any suggestion, or speculation as to the reason for the name 'Rogue One' for the next Star Wars film?   To me, the name seems very close to the Rogue Squadron, most known from Hoth (their leader Luke Skywalker), especially the number following Rogue like a callsign.   However as far as I know, they were formed after the first Death Star destruction. So why Rogue One? Why can't we downvote our own posts? Once in a blue moon, I've wanted the ability to downvote my own answer to some question.  ()  Obviously upvoting one's own posts is out of the question.  But down is different.  Voting my own answer down can help me improve the site by pushing my answer lower in the ranking than another answer with a better or more situation-appropriate alternative.  It's not something I'd do often, but I would use this feature if it were available.  If implemented, I'd expect this feature to operate just like downvotes on other user's posts.  That is:   I get a few seconds to undo the downvote;  I get to remove the downvote after an edit to the post;  I lose a point for placing the downvote (CW excepted); I lose two points for receiving the downvote (CW excepted).   If you're noticing that I'd lose 3 points for downvoting my own non-CW post, congratulations! You can add!  I can think of a couple of potential downsides to this change.  The first one may be a dealbreaker; the second is probably not that big a deal.   Strategic downvoting of oneself: since you can undo the vote after an edit, and you can always edit your own posts, someone could downvote themselves soon after posting (especially on a FGITW answer) to garner extra sympathy upvotes. Badge collecting: the Peer Pressure badge just got easier, because if you have a -2 score on an answer, just downvote and delete for an instant badge. How do I get a block with data to place myself? Are you looking for how to use /setblock with blocks with data? See .  How do I get a block with data in my inventory so I can place it myself? In Java Edition, these commands work: give @s chest{BlockEntityTag:{Items:[{id:&quot;diamond&quot;,count:10b}]}} give @s sign{BlockEntityTag:{Text1:&quot;{\&quot;text\&quot;:\&quot;foo\&quot;,\&quot;bold\&quot;:true}&quot;}}  How can I do this in Bedrock Edition, where there is no access to NBT tags from commands? My storage was not updated