When trying to compile the code below, I get the following error:  $ g++ -std=c++11 main.cpp src/matrix.cpp /tmp/ccsVOKfQ.o: In function `main': main.cpp:(.text+0x1b): undefined reference to `matrix&lt;int&gt;::matrix(unsigned int, int)' main.cpp:(.text+0x2c): undefined reference to `matrix&lt;int&gt;::operator[](int)' collect2: error: ld returned 1 exit status   As far as I know all the code is included correctly, it even worked fine in Visual Studio, but for some reason refuses to compile in GCC on Linux, giving the above error.  My Code:  src/matrix.hpp:  #ifndef __matrix_hpp #define __matrix_hpp #include &lt;vector&gt; #include "../lib/typedefs.hpp"  // abstraction layer on top of 2D vector template &lt;typename t&gt; class matrix { private:   std::vector&lt;std::vector&lt;t&gt;&gt; _mat;   uint _size; public:   matrix(uint, t);   std::vector&lt;t&gt; get_row(int);   std::vector&lt;t&gt; get_column(int);   std::vector&lt;t&gt;&amp; operator[](int);   matrix transpose(); };  #endif   src/matrix.cpp:  #include "matrix.hpp"  template &lt;typename t&gt; matrix&lt;t&gt;::matrix(uint size, t default_val) {   _size = size;   _mat = std::vector&lt;std::vector&lt;t&gt;&gt;(_size, std::vector&lt;t&gt;(_size, default_val)); }  template &lt;typename t&gt; std::vector&lt;t&gt; matrix&lt;t&gt;::get_row(int row_number) {   return _mat[row_number]; }  template &lt;typename t&gt; std::vector&lt;t&gt; matrix&lt;t&gt;::get_column(int col_number) {   std::vector&lt;t&gt; column;    for (int r = 0; r &lt; _size; r++)     column.push_back(_mat[r][col_number]);    return column; }  // provided as alternative notation to get_row template &lt;typename t&gt; std::vector&lt;t&gt;&amp; matrix&lt;t&gt;::operator[](int i) {   return get_row(i); }   main.cpp:  #include &lt;iostream&gt; #include &lt;cstdio&gt; #include "src/matrix.hpp"  int main() {   matrix&lt;int&gt; m(9, 0); // test constructor   m[1][2] = 100; // test operator overload   return 0; }   How can I resolve this issue and make the code compile?
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.)
How to prove Euler's formula: $e^{i\varphi}=\cos(\varphi) +i\sin(\varphi)$? Could you provide a proof of Euler's formula: $e^{i\varphi}=\cos(\varphi) +i\sin(\varphi)$? The  was deleted last night by the Community user.    Normally, I wouldn't see an issue with this, but for this particular deletion, I can see three issues:   We try not to delete good content There are multiple upvoted answers We often use previous answers on Meta (as well as badly asked questions) to form the precedent (and to use as duplicates) when users ask questions like this in the future   On a personal note, I find it easier to link to one of my previous answers whenever possible.  This seems like a bug with the deletion algorithm, , the deletion algorithm should never delete questions with upvoted answers.  I'm going to go ahead and undelete it, but I'm bringing this up in case there was either:    A policy change A bug   So is it either of the above or something else? I am going to start a phd at the US with an F1 visa. University told me that I could enter the US only 30 days before the date on I-20. Since English is not my first language (and this would be a big change in my life) I would like to go there by June.  The thing is that I have an European passport with a valid ESTA. My plan would be to arrive with this passport, stay 4-6 weeks , go to Canada for a short vacation (maybe flight maybe by land) and come back to the USA with F1 visa.  I have two questions about this:  1) is this possible?   2) If yes, how could I justify knowing I will lose my come-back flight during my first entry? (I would purchase round trip because one-way are too expensive, probably with less than 90 days difference) Ways to evaluate $\int \sec \theta \, \mathrm d \theta$ The standard approach for showing $\int \sec \theta \, \mathrm d \theta = \ln|\sec \theta + \tan \theta| + C$ is to multiply by $\dfrac{\sec \theta + \tan \theta}{\sec \theta + \tan \theta}$ and then do a substitution with $u = \sec \theta + \tan \theta$. I like the fact that this trick leads to a fast and clean derivation, but I also find it unsatisfying: It's not very intuitive, nor does it seem to have applicability to any integration problem other than $\int \csc \theta \,\mathrm d \theta$.  Does anyone know of another way to evaluate $\int \sec \theta \, \mathrm d \theta$? In a USB cable, is it OK to swap the D+ and D- wires? I heard that D+ and D- are differential signals, does it matter if I swap them when connecting a USB device to the computer? Can I play a save from the non-GOTY edition of Red Dead Redemption in the GOTY edition? My friend is able to lend me Red Dead Redemption. However it's the vanilla edition, so I'm going to end up buying the GOTY edition anyway. Here is a question now: If I were to play Red Dead Redemption, non-GOTY edition, have a save from it, and then buy the GOTY edition, will I be able to play on the save I made while playing the non-GOTY edition? Banner ads should not be shown on the right-hand ad slot How to make a disk image and restore from it later? Currently, moderators have the ability to reset a user's username and/or profile text, and propagate that to the rest of the network, resetting it everywhere. However, often, the user's stackexchange.com network profile will also need to be reset, and this is currently only possible to do by either the user in question or staff.  Instead of bothering staff every time, moderators should have something available similar to chat, where moderators can change a user's parent site and have access to a "refresh profile" button, which will fetch updated information such as username and avatar from the parent site.  Currently, the only thing that moderators can do on stackexchange.com is to see hidden accounts. It would make sense for moderators to be able to refresh profiles there, like chat, and avoid pinging CMs every time this comes up. Prevent questions on Hot List from being upvoted by casual visitors (only rep is from association bonus) Why does unlocking the bootloader wipe phone? How do I find packages to install via apt-get Retrieve Preview Image URL of Salesforce Image Files Chess Piece Combinations I came across a question yesterday about combinations, and I wanted to know what the correct answer was. The question states as follows:  There are 8 spaces that are alternately black and white. There is one king, one queen, two identical rooks, two identical bishops, and two identical knights. The king needs to be surrounded by the two rooks. Then, the two bishops can be put on any of the remaining spaces as long as one is on a black space and the other is on a white space. Finally, the queen and the knights can be placed anywhere in the remaining spaces in relation to the other pieces. How many possible arrangements are there considering these conditions? Sounds simple but I seem to fail every time, that is it turns into scrambled eggs instead. How do you make it so that you can flip it over both without it breaking and before it burns? proving combinatorics identity - $\sum_{k=0}^m{n-k \choose m-k}={n+1 \choose m}$ Is it possible to experimentally show that observable universe is much larger than ~93B ly? If I read the sentence     Find ten apples and oranges.   Do I need to find ten or twenty pieces of fruit? How to execute consecutive commands from history? Suppose I want to execute a sequence of four commands that I have executed before. If the first one is 432 in the command-history, then I could do:  $ !432; !433; !434; !435   I'm curious, is there a more efficient way to accomplish this? I was confused, trying to copy some files from one PC to another. I have it figured out, but the syntax is still confusing to me. This works:  scp ~/Desktop/Volenteer.png jay@server.ip:~j0h/b   which puts Volenteer.png in the folder /home/j0h/b.  However, this doesn't work:  scp ~Desktop/Volenteer.png     jay@server.ip:~j0h/b   This also fails, giving an exit status 1 file not found:  scp ~/Desktop/Volenteer.png     jay@server.ip:~/j0h/b   As does this:  scp ~Desktop/Volenteer.png     jay@server.ip:~j0h/b   So clearly, there is some difference between ~ and ~/ That difference is the presence of /   $~/ bash: /home/j0h/: Is a directory $ ~ bash: /home/j0h: Is a directory   So why in scp, does the ~ resolve to ~/ ? That is a guess, I cant verify that's what is happening.  But it seems inconsistent, and therefore confusing.  Is this a bug in scp? or is there something about tilde I am missing?