I have some problem now with converting the c++ class into python code using swig.   This is my header file:  template&lt;typename T&gt; class Dictionary {     private:         int size;         T *array;     public:         Dictionary(int s);         void set(int elem, T val);         void get();         ~Dictionary(); };   This is my cpp file:  template&lt;typename T&gt; Dictionary&lt;T&gt;::Dictionary(int s) {     this-&gt;size = s;     this-&gt;array = new T[s]; }  template&lt;typename T&gt; void Dictionary&lt;T&gt;::set(int elem, T val) {     array[elem] = val; }  template&lt;typename T&gt; void Dictionary&lt;T&gt;::get() {     for(int i=0; i&lt;this-&gt;size; i++) {         cout &lt;&lt; i &lt;&lt; array[i] &lt;&lt; typeid(array[i]).name() &lt;&lt; endl;     } }  template&lt;typename T&gt; Dictionary&lt;T&gt;::~Dictionary() { }   And my interface file:  %module Dictionary %{   #include "Dictionary.h" %} %include &lt;std_string.i&gt; %include &lt;std_vector.i&gt; %include "stl.i" %template(_string_list) std::vector&lt; std::string &gt;; %include "Dictionary.h" %template(dictint) Dictionary&lt;int&gt;;   The problem is that I always get an error like undefined symbols for architecture  Undefined symbols for architecture x86_64: "Dictionary&lt;int&gt;::get()", referenced from:   _wrap_dictint_get(_object*, _object*) in Dictionary_wrap.o "Dictionary&lt;int&gt;::set(int, int)", referenced from:   _wrap_dictint_set(_object*, _object*) in Dictionary_wrap.o "Dictionary&lt;int&gt;::Dictionary(int)", referenced from:   _wrap_new_DictionaryD(_object*, _object*) in Dictionary_wrap.o "Dictionary&lt;int&gt;::~Dictionary()", referenced from:   _wrap_delete_dictint(_object*, _object*) in Dictionary_wrap.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)   I wrote this command:  At first swig -c++ -python -py3 Dictionary.i  The second one is: g++ -g -ggdb -c -std=c++0x -I/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/include/python3.7m Dictionary.cpp Dictionary_wrap.cxx  And the third: gcc -dynamiclib -o _Dictionary.so *.o -L/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/ -lpython3.7 -flat_namespace  And on the third line, it crashed. Please help me
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.)
45902
In our C++ course they suggest not to use C++ arrays on new projects anymore. As far as I know Stroustroup himself suggests not to use arrays. But are there significant performance differences?
95713
While developing a C++ application, I had to use a 3rd party library which produced a huge amount of warnings related with a harmless #pragma directive being used.  ../File.hpp:1: warning: ignoring #pragma ident In file included from ../File2.hpp:47,                  from ../File3.hpp:57,                  from File4.h:49,   Is it possible to disable this kind of warnings, when using the GNU C++ compiler?
69649
I'm using GCC; __FILE__ returns the current source file's entire path and name: /path/to/file.cpp. Is there a way to get just the file's name file.cpp (without its path) at compile time? Is it possible to do this in a portable way? Can template meta programming be applied to strings?  I am using this in an error logging macro. I really do not want my source's full path making its way into the executable.
48897
I have a C++ library that provides various classes for managing data.  I have the source code for the library.  I want to extend the C++ API to support C function calls so that the library can be used with C code and C++ code at the same time.  I'm using GNU tool chain (gcc, glibc, etc), so language and architecture support are not an issue.  Are there any reasons why this is technically not possible?  Are there any gotcha's that I need to watch out for?  Are there resources, example code and/or documentation available regarding this?    Some other things that I have found out:   Use the following to wrap your C++ headers that need to be used by C code.     #ifdef __cplusplus extern "C" {   #endif   //   // Code goes here ...   //   #ifdef __cplusplus   } // extern "C"   #endif    Keep "real" C++ interfaces in separate header files that are not included by C.  Think  here.  Using #ifndef __cplusplus #error stuff helps here to detect any craziness. Careful of C++ identifiers as names in C code Enums varying in size between C and C++ compilers.  Probably not an issue if you're using GNU tool chain, but still, be careful. For structs follow the following form so that C does not get confused.  typedef struct X { ... } X  Then use pointers for passing around C++ objects, they just have to be declared in C as struct X where X is the C++ object.   All of this is courtesy of a friend who's a wizard at C++.
113530
I want to make this specialized w/o changing main. Is it possible to specialize something based on its base class? I hope so.  -edit-  I'll have several classes that inherit from SomeTag. I don't want to write the same specialization for each of them.  class SomeTag {}; class InheritSomeTag : public SomeTag {};  template &lt;class T, class Tag=T&gt; struct MyClass { };  template &lt;class T&gt; struct MyClass&lt;T, SomeTag&gt; {     typedef int isSpecialized; };  int main() {     MyClass&lt;SomeTag&gt;::isSpecialized test1; //ok     MyClass&lt;InheritSomeTag&gt;::isSpecialized test2; //how do i make this specialized w/o changing main()     return 0; }
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?
16612
I have got a template class as follows:  class MyClass&lt;T&gt; {     T field;     public void myMethod()     {        field = new T(); // gives compiler error     } }   How do I create a new instance of T in my class?
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?
72798
How feasible would it be to compile Python (possibly via an intermediate C representation) into machine code?  Presumably it would need to link to a Python runtime library, and any parts of the Python standard library which were Python themselves would need to be compiled (and linked in) too.  Also, you would need to bundle the Python interpreter if you wanted to do dynamic evaluation of expressions, but perhaps a subset of Python that didn't allow this would still be useful.  Would it provide any speed and/or memory usage advantages?  Presumably the startup time of the Python interpreter would be eliminated (although shared libraries would still need loading at startup).
59937
I am looking for a way to identify primitives types in a template class definition.  I mean, having this class :  template&lt;class T&gt; class A{ void doWork(){    if(T isPrimitiveType())      doSomething();    else      doSomethingElse();  } private: T *t;  };   Is there is any way to "implement" isPrimitiveType().
33360
OK, I've been staring at this for an hour.  I know there's an error in this frame, as the document compiles fine if I put \end{document} in the frame before this.  But this frame gives an error   File ended while scanning use of \next   Where is it?????  \begin{frame}[fragile] \frametitle{PROC TEMPLATE for a fancy graph (part 1)} \begin{alltt} proc template;  define statgraph scatdens2;  begingraph;   *BEGIN DEFINING THE GRAPH;    entrytitle "Scatter plot with density plots";     *CREATE A TITLE;    layout lattice/columns = 2 rows = 2     columnweights = (.8 .2) rowweights = (.8 .2)       columndatarange = union rowdatarange = union;    *LAYOUT LATTICE...SETS UP A GRID OF GRAPHS;    *COLUMNWEIGHTS AND ROWWEIGHTS SETS     THE RELATIVE SIZE OF THE INDIVIDUAL COLUMNS AND ROWS;  \end{alltt}  \end{frame}
22097
I'm currently working on some logging code that supposed to - among other things - print information about the calling function. This should be relatively easy, standard C++ has a type_info class. This contains the name of the typeid'd class/function/etc. but it's mangled. It's not very useful. I.e. typeid(std::vector&lt;int&gt;).name() returns St6vectorIiSaIiEE.  Is there a way to produce something useful from this? Like std::vector&lt;int&gt; for the above example. If it only works for non-template classes, that's fine too.  The solution should work for gcc, but it would be better if I could port it. It's for logging so it's not so important that it can't be turned off, but it should be helpful for debugging.
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.
103430
My personal style with C++ has always to put class declarations in an include file, and definitions in a .cpp file, very much like stipulated in . Admittedly, part of the reason I like this style probably has to do with all the years I spent coding Modula-2 and Ada, both of which have a similar scheme with specification files and body files. I have a coworker, much more knowledgeable in C++ than I, who is insisting that all C++ declarations should, where possible, include the definitions right there in the header file. He's not saying this is a valid alternate style, or even a slightly better style, but rather this is the new universally-accepted style that everyone is now using for C++. I'm not as limber as I used to be, so I'm not really anxious to scrabble up onto this bandwagon of his until I see a few more people up there with him. So how common is this idiom really? Just to give some structure to the answers: Is it now The Way™, very common, somewhat common, uncommon, or bug-out crazy?
14677
I would like to call python script files from my c++ program.   I am not sure that the people I will distribute to will have python installed.  Basically I'm looking for a .lib file that I can use that has an Apache like distribution license.
52595
I'm trying to parse an INI file using C++. Any tips on what is the best way to achieve this? Should I use the Windows API tools for INI file processing (with which I am totally unfamiliar), an open-source solution or attempt to parse it manually?