I am trying to make a simple linked list, and I came across a LNK2019 when I started to add code to my main function. It was compiling before, but when I added code to my main, I got several errors. I have all my header files included in my main CPP file, and I checked for circular includes. I haven't used C++ in a while, so sorry if this seems obvious. I went with the precompiled headers option when I made the project, if that means anything. What am I messing up?  Errors:  1&gt;RandomCPP.obj : error LNK2019: unresolved external symbol "public: __thiscall List&lt;int&gt;::List&lt;int&gt;(void)" (??0?$List@H@@QAE@XZ) referenced in function _wmain 1&gt;RandomCPP.obj : error LNK2019: unresolved external symbol "public: __thiscall List&lt;int&gt;::~List&lt;int&gt;(void)" (??1?$List@H@@QAE@XZ) referenced in function _wmain 1&gt;RandomCPP.obj : error LNK2019: unresolved external symbol "public: void __thiscall List&lt;int&gt;::add(int const &amp;)" (?add@?$List@H@@QAEXABH@Z) referenced in function _wmain 1&gt;RandomCPP.obj : error LNK2019: unresolved external symbol "public: int * __thiscall List&lt;int&gt;::get(int)const " (?get@?$List@H@@QBEPAHH@Z) referenced in function _wmain   List.h:  #pragma once #include "ListNode.h"  template&lt;class T&gt; class ListNode;  template&lt;class T&gt; class List { public:     List&lt;T&gt;();     ~List&lt;T&gt;();      void add(const T&amp;);     void insert(int, const T&amp;);     void clear();     bool isEmpty() const;     T* get(const int) const;     int getLength() const;      void foreach(void(*foo)(T)) const;      T* operator[](const int index) const;  private:     ListNode&lt;T&gt;* firstElement;     ListNode&lt;T&gt;* lastElement;      //Utility     ListNode&lt;T&gt;* getNewNode(const T&amp;);     ListNode&lt;T&gt;* getNode(int index) const; };   ListNode.h:  #pragma once  template&lt;class T&gt; class List;  template &lt;class T&gt; class ListNode {     friend class List &lt; T &gt; ;  public:     ListNode(const T&amp; data);     ~ListNode();      T getData() const;  private:     T data;     ListNode&lt;T&gt; *nextPtr; };   RandomCPP.cpp (Main File):  #include "stdafx.h" #include "List.h" #include "ListNode.h"  using namespace std;  int _tmain(int argc, _TCHAR* argv[]) {     List&lt;int&gt; values = List&lt;int&gt;();     values.add(0);     values.add(1);     values.add(2);     values.add(3);     values.add(4);      cout &lt;&lt; values.get(0) &lt;&lt; endl         &lt;&lt; values.get(1) &lt;&lt; endl         &lt;&lt; values.get(2) &lt;&lt; endl         &lt;&lt; values.get(3) &lt;&lt; endl         &lt;&lt; values.get(4) &lt;&lt; endl &lt;&lt; endl;      system("pause");     return 0; }   stdafx.h:  #pragma once  #include "targetver.h"  #include &lt;stdio.h&gt; #include &lt;tchar.h&gt; #include &lt;iostream&gt;   I have a List.cpp file and a ListNode.cpp file, each of which contain the definitions of the class declared in the corresponding .h file, and nothing else. The stdafx.cpp file is empty except an include of stdafx.h.
341
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.)
109393
Consider the following code:  template&lt;class T&gt; class Foo { public:   Foo() { a = 1; }  protected:   int a; };  template&lt;class T&gt; class Bar : public Foo&lt;T&gt; { public:   Bar() { b = 4; };    int Perna(int u);  protected:   int b;  };  template&lt;class T&gt; int Bar&lt;T&gt;::Perna(int u)  {    int c = Foo&lt;T&gt;::a * 4; // This works   return (a + b) * u;    // This doesn't }   g++ 3.4.6, 4.3.2 and 4.1.2 give error   test.cpp: In member function `int Bar&lt;T&gt;::Perna(int)': test.cpp:25: error: `a' was not declared in this scope   g++ 2.96 and MSVC 6, 7, 7.1, 8 and 9 accept it, as do (at least) older Intel and SGI c++ compilers.   Do the new Gnu C++ compiler obey the standard or not? If they do, what is the rationale behind that inheriting class is not able to see a protected inherited member variable?  Also, if there's  int A() { return a; }    in Foo, I get error  test.cpp:25: error: there are no arguments to A that depend on a template parameter, so a declaration of A must be available test.cpp:25: error: (if you use -fpermissiveâ, G++ will accept your code, but allowing the use of an undeclared name is deprecated)   when I try to use it in a member function of Bar. I find that curious as well: Bar inherits Foo, so I think it's obvious that A() in scope of Bar is Foo::A().
99180
I'm used to doing all my coding in one C file. However, I'm working on a project large enough that it becomes impractical to do so. I've been #including them together but I've run into cases where I'm #including some files multiple times, etc. I've heard of .h files, but I'm not sure what their function is (or why having 2 files is better than 1).  What strategies should I use for organizing my code? Is it possible to separate "public" functions from "private" ones for a particular file?   question precipitated my inquiry. The tea.h file makes no reference to the tea.c file. Does the compiler "know" that every .h file has a corresponding .c file?
80212
For many questions the answer seems to be found in "the standard". However, where do we find that? Preferably online.  Googling can sometimes feel futile, again especially for the C standards, since they are drowned in the flood of discussions on programming forums.  To get this started, since these are the ones I am searching for right now, where are there good online resources for:   C89 C99 C11 C++98 C++03 C++11 C++14 C++17
52812
I've created a new C++ project in Visual Studio 2008.  No code has been written yet;  Only project settings have been changed.  When I compile the project, I receive the following fatal error:     fatal error LNK1104: cannot open file 'C:\Program.obj'
89268
I'm building a project using a GNU tool chain and everything works fine until I get to linking it, where the linker complains that it is missing/can't find crti.o. This is not one of my object files, it seems to be related to libc but I can't understand why it would need this crti.o, wouldn't it use a library file, e.g. libc.a?  I'm cross compiling for the arm platform. I have the file in the toolchain, but how do I get the linker to include it?   crti.o is on one of the 'libraries' search path, but should it look for .o file on the library path?   Is the search path the same for gcc and ld?
62585
Given the following example, why do I have to explicitly use the statement b-&gt;A::DoSomething() rather than just b-&gt;DoSomething()?  Shouldn't the compiler's overload resolution figure out which method I'm talking about?  I'm using Microsoft VS 2005. (Note: using virtual doesn't help in this case.)  class A {   public:     int DoSomething() {return 0;}; };  class B : public A {   public:     int DoSomething(int x) {return 1;}; };  int main() {   B* b = new B();   b-&gt;A::DoSomething();    //Why this?   //b-&gt;DoSomething();    //Why not this? (Gives compiler error.)   delete b;   return 0; }
983
I have some template code that I would prefer to have stored in a CPP file instead of inline in the header.  I know this can be done as long as you know which template types will be used.  For example:  .h file  class foo { public:     template &lt;typename T&gt;     void do(const T&amp; t); };   .cpp file  template &lt;typename T&gt; void foo::do(const T&amp; t) {     // Do something with t }  template void foo::do&lt;int&gt;(const int&amp;); template void foo::do&lt;std::string&gt;(const std::string&amp;);   Note the last two lines - the foo::do template function is only used with ints and std::strings, so those definitions mean the app will link.  My question is - is this a nasty hack or will this work with other compilers/linkers? I am only using this code with VS2008 at the moment but will be wanting to port to other environments.
50795
I am programming in C++ for many years, still I have doubt about one thing. In many places in other people code I see something like:  void Classx::memberfunction() {     this-&gt;doSomething(); }   If I need to import/use that code, I simply remove the this-> part, and I have never seen anything broken or having some side-effects.  void Classx::memberfunction() {     doSomething(); }   So, do you know of any reason to use such construct?  EDIT: Please note that I'm talking about member functions here, not variables. I understand it can be used when you want to make a distinction between a member variable and function parameter.  EDIT: apparent duplicate:
21491
Why does C++ have header files and .cpp files?
82685
I checked out a copy of a C++ application from SourceForge (HoboCopy, if you're curious) and tried to compile it.  Visual Studio tells me that it can't find a particular header file. I found the file in the source tree, but where do I need to put it, so that it will be found when compiling?    Are there special directories?
8198
I am writing a small matrix library in C++ for matrix operations. However my compiler complains, where before it did not. This code was left on a shelf for 6 months and in between I upgraded my computer from debian etch to lenny (g++ (Debian 4.3.2-1.1) 4.3.2 ) however I have the same problem on a Ubuntu system with the same g++.  Here is the relevant part of my matrix class:  namespace Math {     class Matrix     {     public:          [...]          friend std::ostream&amp; operator&lt;&lt; (std::ostream&amp; stream, const Matrix&amp; matrix);     } }   And the "implementation":  using namespace Math;  std::ostream&amp; Matrix::operator &lt;&lt;(std::ostream&amp; stream, const Matrix&amp; matrix) {      [...]  }   This is the error given by the compiler:     matrix.cpp:459: error: 'std::ostream&amp;   Math::Matrix::operator&lt;&lt;(std::ostream&amp;,   const Math::Matrix&amp;)' must take   exactly one argument   I'm a bit confused by this error, but then again my C++ has gotten a bit rusty after doing lots of Java those 6 months. :-)
83233
I can compile this table separately but when I want to compile the whole file, it gives me an error, which is fixed by removing \multirow.  \usepackage{multirow}  \begin{table}[htbp] \begin{center} \begin{tabular}{|c|c|c|c|p{1cm}p{1cm}p{1cm}p{1cm}p{1cm}p{1cm}p{1cm}|} \hline A &amp; B &amp; C &amp; D &amp; \multicolumn{7}{|c|}{F}  \\ \hline \multirow{ 2}{}{1} &amp; 0 &amp; 6 &amp; 230 &amp; 35 &amp; 40 &amp; 55 &amp; 25 &amp; 40 &amp; 35 &amp; \\ &amp; 1 &amp; 5 &amp; 195 &amp; 25 &amp; 50 &amp; 35 &amp; 40 &amp; 45 &amp;  &amp;  \\ \hline \end{tabular} \end{center} \label{table2} \end{table}
12325
The question was asked many times in many ways, but unfortunately is not covered well in most of the answers. I'm having the same issue doing things using include-files.  In my TwentyFourteen child theme's functions.php I used:  require_once get_stylesheet_directory_uri() .'/admin-panel/theme-options.php';   And I'm using . I've used it in many of my projects, the same way mentioned here, without having the error. But recently I'm having the issue in several of my projects. If I take the code to functions.php then everything's fine. But it's occurring only when I'm trying to include/require external file.  I'm having the error:     Fatal error: Call to undefined function add_action() in C:\xampp\htdocs\project\wp-content\themes\my-theme\admin-panel\theme-options.php on line 2   In this case I'm having the error using a child theme (of T14). But even in one of my parent theme I'm facing the issue. But in the same environment my other projects are running well with all the includes and/or requires (where several add_action()s are defined). I'm having issues in ALL the add_action() calls, like CPT assigning, Custom Taxonomy assigning etc. But I'm successfully developing another two projects including external files from inc/ folder where all my CPTs are assigned and their meta boxes too.  I tried reinstalling WordPress, deactivating all my plugins, tried from Child Theme, tried only the same thing by modifying TwentyFifteen (applying default theme), tried require(), require_once(), include(), include, require_once, and require one after another with failure. And I'm using WP 4.1.1 in all the good and problematic installs.  Majority of the previous questions are answered with a simple line:     As the message says, you haven defined the function add_action() and yet you're trying to use it.   But,   how come (isn't it already defined by WordPress)? and why it's differing project to project in the same environment (How come it's out of the scope now only in particular project[s])?
109435
What is the syntax and which namespace/class needs to be imported? Give me sample code if possible. It would be of great help.
10581
I have the following code:  typedef void VOID; int f(void); int g(VOID);   which compiles just fine in C (using gcc 4.3.2 on Fedora 10). The same code compiled as C++ gives me the following error:  void.c:3: error: ‘&lt;anonymous&gt;’ has incomplete type void.c:3: error: invalid use of ‘VOID’   Now, this is something in external library and I would like the owner to fix that problem. So I have a question - does C++ standard forbids this construct? Could you give me a pointer/citation? The only thing I can recall is that function declaration with (void) to signal empty parameter list is deprecated in C++, but I don't understand why typedefed VOID does not work.
1377
Is there any good reason that an empty set of round brackets (parentheses) isn't valid for calling the default constructor in C++?  MyObject  object;  // ok - default ctor MyObject  object(blah); // ok  MyObject  object();  // error   I seem to type "()" automatically everytime. Is there a good reason this isn't allowed?