I am learning how to use template in c++ language ,my program is just simple linear search program which i use just for understanding purpose while compiling the program compiler constantly giving me this linker error   Error   1   error LNK2019: unresolved external symbol "public: __thiscall searching&lt;int&gt;::searching&lt;int&gt;(int)" (??0?$searching@H@@QAE@H@Z) referenced in function _main C:\Users\Sachin\Documents\Visual Studio 2012\C++\template\template\Source.obj   template Error   2   error LNK2019: unresolved external symbol "public: __thiscall searching&lt;int&gt;::~searching&lt;int&gt;(void)" (??1?$searching@H@@QAE@XZ) referenced in function _main    C:\Users\Sachin\Documents\Visual Studio 2012\C++\template\template\Source.obj   template Error   3   error LNK2019: unresolved external symbol "public: void __thiscall searching&lt;int&gt;::set_data(void)" (?set_data@?$searching@H@@QAEXXZ) referenced in function _main   C:\Users\Sachin\Documents\Visual Studio 2012\C++\template\template\Source.obj   template Error   4   error LNK2019: unresolved external symbol "public: void __thiscall searching&lt;int&gt;::get_data(void)" (?get_data@?$searching@H@@QAEXXZ) referenced in function _main   C:\Users\Sachin\Documents\Visual Studio 2012\C++\template\template\Source.obj   template   Header.h  #include&lt;iostream&gt; using namespace std; typedef int BOOL; #define TRUE 1 #define FALSE 0  template &lt;class t&gt; class searching { private :     t *ptr;     int isize;     BOOL sort;  public:     searching(int);     searching(searching &amp;);     ~searching();      BOOL linearsearch(t);     BOOL linearsearchbi(t);     BOOL binarysearch(t);     void set_data();     void get_data();     BOOL chechsorted();  };   main.cpp  #include "Header.h"  int main() {      searching &lt;int&gt;obj1(10);     //searching &lt;float&gt;obj2;       obj1.set_data();     obj1.get_data();     obj1.linearsearch(5);     return 0; }   helper.cpp  #include"Header.h"  template &lt;class t&gt; searching &lt;t&gt;::searching(int ino) {     isize =ino;     ptr= new &lt;t&gt; [isize]; }  template &lt;class t&gt; searching &lt;t&gt; ::searching(searching  &amp;ref) {     isize=ref.isize;     ptr=new &lt;t&gt;[isize];      for(int i=0;i&lt;isize;i++)     {         ptr[i]=ref.ptr[i];     } }  template &lt;class t&gt; searching &lt;t&gt;::~searching() {     delete []ptr; }  template &lt;class t&gt; void searching &lt;t&gt;::set_data() {     cout&lt;&lt;"Enter "&lt;&lt;isize&lt;&lt;" element"&lt;&lt;endl;     for(int i=0;i&lt;isize;i++)     {         cin&gt;&gt;ptr[i];     } }  template &lt;class t&gt; void searching &lt;t&gt; ::get_data() {     cout&lt;&lt;"Eelements are :"&lt;&lt;endl;     for(int i=0;i&lt;isize;i++)     {         cout&lt;&lt;ptr[i]&lt;&lt;endl;     } }  template &lt;class t&gt; BOOL searching &lt;t&gt;::linearsearch(t value) {     int i=0;      for(i=0;i&lt;isize;i++)     {         if(ptr[i]==value)         break;     }     if(i==isize)     {         return FALSE;     }     else     {         return TRUE;     } }   I have tried moving all the definitions from the helper.cpp to header under class but compiler still gives me error is there any thing i need to change in this code please guide me. Thanks in advance.
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.)
42167
The following code:  template &lt;typename S, typename T&gt; struct foo {    void bar(); };  template &lt;typename T&gt; void foo &lt;int, T&gt;::bar() { }   gives me the error  invalid use of incomplete type 'struct foo&lt;int, T&gt;' declaration of 'struct foo&lt;int, T&gt;'   (I'm using gcc.) Is my syntax for partial specialization wrong? Note that if I remove the second argument:  template &lt;typename S&gt; struct foo {    void bar(); };  template &lt;&gt; void foo &lt;int&gt;::bar() { }   then it compiles correctly.
15520
My question is about when a function should be referenced with the extern keyword in C. I am failing to see when this should be used in practice.  As I am writing a program all of the functions that I use are made available through the header files I have included.  So why would it be useful to extern to get access to something that was not exposed in the header file? I could be thinking about how extern works incorrectly, and if so please correct me. Also.. Should you extern something when it is the default declaration without the keyword in a header file?
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. :-)
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
91114
I had this table working with an IEEETemplate but now when I try to build it with an IET Template I get the error that you can see on the title .. could anybody help me?  Thank very much for your time.  \documentclass{cta-author}   \usepackage{graphicx} \usepackage{multirow} \usepackage{booktabs}  \begin{document}  \begin{table}[h!]     \centering   \renewcommand{\arraystretch}{1.2}   \begin{tabular}[b]{|p{1cm}|l|c|c|c|c|}     \hline     \multirow{2}{0.3cm}{\textbf{j}}&amp; \multicolumn{2}{c|}{\textbf{k}}  &amp; \multicolumn{2}{c|}{\textbf{l}}\\     \cline{2-5}     &amp; \textbf{f} &amp; \textbf{g} &amp; \textbf{h} &amp; \textbf{i}  \\ \hline        a  &amp; b  &amp; c &amp; d &amp; e \\ \hline     \end{tabular}     \caption{Example} \end{table}  \end{document}
3559
In the C and C++ programming languages, what is the difference between using angle brackets and using quotes in an include statement, as follows?   #include &lt;filename&gt;  #include "filename"
21871
I am trying to pass a reference to a two-dimensional array to a function in C++. I know the size of both dimensions at compile time. Here is what I have right now:  const int board_width = 80; const int board_height = 80; void do_something(int[board_width][board_height]&amp; array);  //function prototype   But this doesn't work. I get this error from g++:  error: expected ‘,’ or ‘...’ before ‘*’ token   What does this error mean, and how can I fix it?
108407
I've just ported over and updated a bunch of FBX model loading code I had that worked with Direct X 10 to try and make it work with Direct X 11. Since that time, the FBX SDK I was using has been updated.   In my old program I linked to the following lib:  fbxsdk-2012.2-mdd.lib   Now, clearly I can't link to this as I don't have 2012.2 on my system. So, my thinking would be simply changing 2012.2 to 2014.1, but this didn't work and lead to the following error:  error LNK1104: cannot open file 'fbxsdk-2014.1-mdd.lib'    So I tried to some googleing to see what the updated version of fbxsdk-2012.2-mdd.lib is. But I can't find anything. I tried taking out linking ot the 2014.1 lib but I get the following errors:     Error 36  error LNK2019: unresolved external symbol "void __cdecl fbxsdk_2014_1::FbxAssert(char const *,char const *,unsigned int,char const *)" (?FbxAssert@fbxsdk_2014_1@@YAXPBD0I0@Z) referenced in function "public: int &amp; __thiscall fbxsdk_2014_1::FbxArray::operatorconst " (??A?$FbxArray@H@fbxsdk_2014_1@@QBEAAHH@Z)    So, looking in the FBX sample directory I opened up the ViewScene sample to see what it lib it linked to and I see that it wanted the following:  libfbxsdk-md.lib   So I did the same. But, my program claims it cannot open the file. And I'm at a loss as to what to do next.   Has anyone successfully managed to load FBX models into a Directx 11 application using 2014.1? If so, what do I need to do to get the correct lib linked?
102790
For deployment reasons, I am trying to use IJW to wrap a C# assembly in C++ instead of using a COM Callable Wrapper.    I've done it on other projects, but on this one, I am getting an EEFileLoadException.  Any help would be appreciated!  Managed C++ wrapper code (this is in a DLL):  extern "C" __declspec(dllexport) IMyObject* CreateMyObject(void) {     //this class references c# in the constructor     return new CMyWrapper( ); }  extern "C" __declspec(dllexport)  void DeleteMyObject(IMyObject* pConfigFile) {     delete pConfigFile; }  extern "C" __declspec(dllexport) void TestFunction(void) {     ::MessageBox(NULL, _T("My Message Box"), _T("Test"), MB_OK); }   Test Code (this is an EXE):  typedef void* (*CreateObjectPtr)(); typedef void (*TestFunctionPtr)();  int _tmain testwrapper(int argc, TCHAR* argv[], TCHAR* envp[]) {     HMODULE hModule = ::LoadLibrary(_T("MyWrapper"));     _ASSERT(hModule != NULL);      PVOID pFunc1 = ::GetProcAddress(hModule, "TestFunction");     _ASSERT(pFunc1 != NULL);     TestFunctionPtr pTest = (TestFunctionPtr)pFunc1;      PVOID pFunc2 = ::GetProcAddress(hModule, "CreateMyObject");     _ASSERT(pFunc2 != NULL);     CreateObjectPtr pCreateObjectFunc = (CreateObjectPtr)pFunc2;      (*pTest)();  //this successfully pops up a message box     (*pCreateObjectFunc)();  //this tosses an EEFileLoadException      return 0; }   For what it's worth, the Event Log reports the following: .NET Runtime version 2.0.50727.143 -  Fatal Execution Engine Error (79F97075) (80131506)  Unfortunately, Microsoft has no information on that error.
18976
Is it possible to write a template that changes behavior depending on if a certain member function is defined on a class?  Here's a simple example of what I would want to write:  template&lt;class T&gt; std::string optionalToString(T* obj) {     if (FUNCTION_EXISTS(T-&gt;toString))         return obj-&gt;toString();     else         return "toString not defined"; }   So, if class T has toString() defined, then it uses it; otherwise, it doesn't. The magical part that I don't know how to do is the "FUNCTION_EXISTS" part.
97800
When I run a process that links to a shared library at runtime (linked when the process starts, not linked later with dlload()), where does it look for that shared library (.so) file other than LD_LIBRARY_PATH?  Background:  I have some C++ code that I wrote that uses a particular third-party library. I have installed the library and compiled my code on two different platforms, both Ubuntu but different versions, and different versions of gcc as well. The library was compiled and installed from source, and is located in /usr/local/lib on both platforms. When I compile my code, I link with the pkg-config --libs parameters for the third-party library and I've verified that pkg-config --libs returns the exact same thing on both platforms.  My code compiles successfully on both platforms, and LD_LIBRARY_PATH is not defined (or defined as empty: "") on both platforms. However, when I run it on one platoform it works fine, and on the other I get this error:  error while loading shared libraries: libthrift-0.9.0.so: cannot open shared object file: No such file or directory   Funnily enough, the ones that doesn't work is the newer version of Ubuntu and gcc.  :/  So I'm trying to figure out how the working one is able to locate the library, so that I can make the broken one locate the library in the same way. (i.e., without setting LD_LIBRARY_PATH)  Update:  Here's my output from cat /etc/ld.so.conf.d/*  ...on the working (older) system:  /usr/lib/mesa /usr/lib32/mesa /usr/lib/alsa-lib # libc default configuration /usr/local/lib # Multiarch support /lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu   ...on the broken (newer) system:  # libc default configuration /usr/local/lib # Multiarch support /lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/mesa
5040
I'm using an API that requires me to pass a function pointer as a callback. I'm trying to use this API from my class but I'm getting compilation errors.   Here is what I did from my constructor:  m_cRedundencyManager-&gt;Init(this-&gt;RedundencyManagerCallBack);   This doesn't compile - I get the following error:      Error  8 error C3867: 'CLoggersInfra::RedundencyManagerCallBack': function call missing argument list; use '&amp;CLoggersInfra::RedundencyManagerCallBack' to create a pointer to member   I tried the suggestion to use &amp;CLoggersInfra::RedundencyManagerCallBack - didn't work for me.   Any suggestions/explanation for this??  I'm using VS2008.  Thanks!!
65547
See also      Not a major issue, just annoying as I don't want my class to ever be instantiated without the particular arguments.  #include &lt;map&gt;  struct MyClass {     MyClass(int t); };  int main() {     std::map&lt;int, MyClass&gt; myMap;     myMap[14] = MyClass(42); }   This gives me the following g++ error:     /usr/include/c++/4.3/bits/stl_map.h:419: error: no matching function for call to ‘MyClass()’   This compiles fine if I add a default constructor; I am certain it's not caused by incorrect syntax.
36051
class Test {        bool isVal() const {           return isVal;       }    private:        bool isVal; };   On Compiling this file it says      testClass.cpp:9: declaration of `bool   Test::isVal'      testClass.cpp:3: conflicts with   previous declaration `bool   Test::isVal()'   Although the same would work for java   class Test {    private boolean isVal;    public boolean isVal() {       return isVal;   }  }   Why does the compile error occur in C++ not in Java?
89614
I am using the following research statement template.  In my statement, I have to use the environment of the theorem, lemma, definition. It is giving me error when I am compiling my LaTeX file. I could not find the error. Any help appreciated.   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % "ModernCV" CV and Cover Letter % LaTeX Template % Version 1.1 (9/12/12) % % This template has been downloaded from: % http://www.LaTeXTemplates.com % % Original author: % Xavier Danaux (xdanaux@gmail.com) % % License: % CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/) % % Important note: % This template requires the moderncv.cls and .sty files to be in the same % directory as this .tex file. These files provide the resume style and themes % used for structuring the document. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %---------------------------------------------------------------------------------------- %   PACKAGES AND OTHER DOCUMENT CONFIGURATIONS %----------------------------------------------------------------------------------------  \documentclass[11pt,a4paper,sans]{moderncv} % Font sizes: 10, 11, or 12; paper sizes: a4paper, letterpaper, a5paper, legalpaper, executivepaper or landscape; font families: sans or roman  \moderncvstyle{casual} % CV theme - options include: 'casual' (default), 'classic', 'oldstyle' and 'banking' \moderncvcolor{blue} % CV color - options include: 'blue' (default), 'orange', 'green', 'red', 'purple', 'grey' and 'black'  \usepackage{lipsum} % Used for inserting dummy 'Lorem ipsum' text into the template  \usepackage[scale=0.75]{geometry} % Reduce document margins %\setlength{\hintscolumnwidth}{3cm} % Uncomment to change the width of the dates column %\setlength{\makecvtitlenamewidth}{10cm} % For the 'classic' style, uncomment to adjust the width of the space allocated to your name  \usepackage{amsfonts, amsthm} \usepackage{amsmath} \usepackage{amssymb} \usepackage{booktabs} \usepackage{color} \usepackage{colortbl} \usepackage{enumitem} \usepackage[utf8]{inputenc} \usepackage[english]{babel} %\usepackage[hang,flushmargin]{footmisc} %\usepackage[margin=25mm]{geometry} %\usepackage{mathtools}  \newtheorem{theorem}{Theorem}[section] \newtheorem{corollary}{Corollary}[theorem] \newtheorem{lemma}[theorem]{Lemma}   %\newtheorem{theorem}{Theorem} %\newtheorem{specialthm}{specialthm} %\renewcommand*{\thespecialthm}{\arabic{specialthm}}   %---------------------------------------------------------------------------------------- %   NAME AND CONTACT INFORMATION SECTION %----------------------------------------------------------------------------------------  \firstname{} % Your first name \familyname{} % Your last name  % All information in this block is optional, comment out any lines you don't need %\title{Research Statement} %\address{}{} %\mobile{()} %\phone{(000) 111 1112} %\fax{(000) 111 1113} %\email{} %\homepage{staff.org.edu/~jsmith}{staff.org.edu/$\sim$jsmith} % The first argument is the url for the clickable link, the second argument is the url displayed in the template - this allows special characters to be displayed such as the tilde in this example %\extrainfo{additional information} %\photo[70pt][0.4pt]{pictures/picture} % The first bracket is the picture height, the second is the thickness of the frame around the picture (0pt for no frame) %\quote{"A witty and playful quotation" - John Smith}  %----------------------------------------------------------------------------------------  \begin{document} \makecvtitle % Print the CV title %---------------------------------------------------------------------------------------- %   EDUCATION SECTION %----------------------------------------------------------------------------------------  \section{Previous Research Experience} \begin{theorem} Hello new \end{theorem}  \begin{lemma} \end{lemma}  {\hskip 2em}     %---------------------------------------------------------------------------------------- \section{Research Goals}      \end{document}
19841
I've been programming in C++ for a few years, and I've used STL quite a bit and have created my own template classes a few times to see how it's done.  Now I'm trying to integrate templates deeper into my OO design, and a nagging thought keeps coming back to me: They're just a macros, really... You could implement (rather UGLY) auto_ptrs using #defines, if you really wanted to.  This way of thinking about templates helps me understand how my code will actually work, but I feel that I must be missing the point somehow. Macros are meant evil incarnate, yet "template metaprogramming" is all the rage.  So, what ARE the real distinctions? and how can templates avoid the dangers that #define leads you into, like   Inscrutable compiler errors in places where you don't expect them? Code bloat?  Difficulty in tracing code? Setting Debugger Breakpoints?