I can't understand why this code gets unresolved externals error.  stack.cpp  #include "stack.h" #include&lt;iostream&gt; using namespace std;  template&lt;int i&gt; st&lt;i&gt;&amp; st&lt;i&gt;::operator=(const st&lt;i&gt; &amp;other){         if(this!=&amp;other){         delete[]anarray;         anarray=new int[i];         for(int i=0;i&lt;10;i++)             anarray[i]=other.anarray[i];}     return *this;     }  template&lt;int i&gt; void st&lt;i&gt;::push(int i2, int val){anarray[i2]=val;}   stack.h  #pragma once   template&lt;int i&gt;  class st{ public: int  *anarray;      st(){anarray=new int[i];}     ~st(){delete[]anarray;};     st&lt;i&gt;&amp; operator=(const st&lt;i&gt; &amp;other);       //int&amp; operator[](int i);     void push(int i, int val); };   main.cpp  #include&lt;iostream&gt; #include"stek.h" using namespace std;  void main(){     cout&lt;&lt;"----"&lt;&lt;endl;     st &lt;10&gt; z1; st&lt;10&gt; z2;     for(int i=0;i&lt;6;i++)     z1.anarray[i]=2*i;     z2=z1; for(int i=0;i&lt;6;i++) cout&lt;&lt;z2.anarray[i]&lt;&lt;endl;     cout&lt;&lt;"----"&lt;&lt;endl;      system("pause"); }   I know how to implement this so it works, but my question is why this particular example doesn't work.
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.)
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}
124139
I have a class which has many small functions. By small functions, I mean functions that doesn't do any processing but just return a literal value. Something like:  string Foo::method() const{     return "A"; }   I have created a header file "Foo.h" and source file "Foo.cpp". But since the function is very small, I am thinking about putting it in the header file itself. I have the following questions:   Is there any performance or other issues if I put these function definition in header file? I will have many functions like this. My understanding is when the compilation is done, compiler will expand the header file and place it where it is included. Is that correct?
15868
Why does this code:  class A {     public:          explicit A(int x) {} };  class B: public A { };  int main(void) {     B *b = new B(5);     delete b; }   Result in these errors:   main.cpp: In function ‘int main()’: main.cpp:13: error: no matching function for call to ‘B::B(int)’ main.cpp:8: note: candidates are: B::B() main.cpp:8: note:                 B::B(const B&)   Shouldn't B inherit A's constructor?  (this is using gcc)
98249
While working on a C++ project, I was looking for a third party library for something that is not my core business. I found a really good library, doing exactly what's needed, but it is written in Python. I decided to experiment with embedding Python code in C++, using the Boost.Python library.  The C++ code looks something like this:  #include &lt;string&gt; #include &lt;iostream&gt; #include &lt;boost/python.hpp&gt;  using namespace boost::python;  int main(int, char **)  {     Py_Initialize();      try      {         object module((handle&lt;&gt;(borrowed(PyImport_AddModule("__main__")))));          object name_space = module.attr("__dict__");         object ignored = exec("from myModule import MyFunc\n"                           "MyFunc(\"some_arg\")\n",                           name_space);          std::string res = extract&lt;std::string&gt;(name_space["result"]);     }      catch (error_already_set)      {         PyErr_Print();     }      Py_Finalize();     return 0; }   A (very) simplified version of the Python code looks like this:  import thirdparty  def MyFunc(some_arg):     result = thirdparty.go()     print result   Now the problem is this:  'MyFunc' executes fine, i can see the print of 'result'. What i cannot do is read 'result' back from the C++ code. The extract command never finds 'result' in any namespace. I tried defining 'result' as a global, i even tried returning a tuple, but i cannot get it to work.
118553
In C++ I can't use a method if I declare it after the calling method.    Does this order matter in other languages like Java or C#?
2864
In C++ the following code gives a compiler error:  void destruct1 (int * item) {   item-&gt;~int(); }   This code is nearly the same, I just typedef the int to another type and something magic happens:  typedef int myint;  void destruct2 (myint * item) {   item-&gt;~myint(); }   Why does the second code work? Does an int get a destructor just because it has been typedefed?  In case you wonder why one ever would like to do this: This comes from refactoring C++ code. We're removing the standard heap and replacing it with selfmade pools. This requires us to call placement-new and the destructors. I know that calling destructors for primitive types is useless, but we want them in the code nevertheless in case we later replace PODs with real classes.  Finding out that naked int's don't work but typedefed ones do was quite a surprise.  Btw - I have a solution that involves template-functions. We just typedef inside the template and everything is fine.
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?
51146
Here is an example of polymorphism from  (edited for readability):  // abstract base class #include &lt;iostream&gt; using namespace std;  class Polygon {     protected:         int width;         int height;     public:         void set_values(int a, int b) { width = a; height = b; }         virtual int area(void) =0; };  class Rectangle: public Polygon {     public:         int area(void) { return width * height; } };  class Triangle: public Polygon {     public:         int area(void) { return width * height / 2; } };  int main () {     Rectangle rect;     Triangle trgl;     Polygon * ppoly1 = &amp;rect;     Polygon * ppoly2 = &amp;trgl;     ppoly1-&gt;set_values (4,5);     ppoly2-&gt;set_values (4,5);     cout &lt;&lt; ppoly1-&gt;area() &lt;&lt; endl; // outputs 20     cout &lt;&lt; ppoly2-&gt;area() &lt;&lt; endl; // outputs 10     return 0; }   My question is how does the compiler know that ppoly1 is a Rectangle and that ppoly2 is a Triangle, so that it can call the correct area() function? It could find that out by looking at the "Polygon * ppoly1 = &rect;" line and knowing that rect is a Rectangle, but that wouldn't work in all cases, would it? What if you did something like this?  cout &lt;&lt; ((Polygon *)0x12345678)-&gt;area() &lt;&lt; endl;   Assuming that you're allowed to access that random area of memory.  I would test this out but I can't on the computer I'm on at the moment.  (I hope I'm not missing something obvious...)
7208
Is it possible to forward declare an standard container in a header file?  For example, take the following code:  #include &lt;vector&gt;  class Foo { private:     std::vector&lt;int&gt; container_;     ... };   I want to be able to do something like this:  namespace std {     template &lt;typename T&gt; class vector; }  class Foo { private:     std::vector&lt;int&gt; container_;     ... };   Can this be done?
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.
102686
I tried this and that, but could not solve this problem. Here is the code that produces this error:  \begin{equation} o=g(h)=\left\{\begin{array}{rcl}     1 &amp; if &amp; h &lt;   0 \\     0 &amp; if &amp; h \le 0  \end{array}\right \end{equation}   The error is given on the line \end{equation} resides. Thanks.
42083
What are the C++ coding and file organization guidelines you suggest for people who have to deal with lots of interdependent classes spread over several source and header files?  I have this situation in my project and solving class definition related errors crossing over several header files has become quite a headache.
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!!
56384
When declaring a template, I am used to having this kind of code:  template &lt;class T&gt;   But , they used:  template &lt;unsigned int N&gt;   I checked that it compiles. But what does it mean? Is it a non-type parameter? And if so, how can we have a template without any type parameter?
123746
I have a problem compiling the following document.  First, I have a file macros.sty that consists of :  \newcommand{\test}{ \xymatrix@R=0mm{x} }   Then, I have an auxiliary file out.aux that consists of :  \test   Finally, the main file is :  \documentclass{article} \usepackage[all]{xy} \usepackage{macros} \begin{document} \input{out.aux} \end{document}   The error message is :  ./out.aux:1: Undefined control sequence. \xymatrix@R -&gt;\Addop@@                     \xymatrixrowsep@ \dimen@ii    Note that if you remove the R=0mm, the problem no longer holds.  Is that a bug ?  It is very strange because I remember to have already used a command similar to \test in an input file without any problem.  Does it come from my distribution ?  Thank you :)
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. :-)