I have a problem with codeblocks ver 10.05. I made a c++ project, and I wrote a program like this:  main.cpp  #include &lt;iostream&gt; #include "vectorddd.hpp"   using namespace std;  int main() {      vector3D&lt;int&gt; tesztinttomb;     tesztinttomb.saveout("igen.dat");     return 0; }   header file (vectorddd.hpp):  #ifndef VECTORDDD_HPP_INCLUDED #define VECTORDDD_HPP_INCLUDED  #include &lt;iostream&gt;  template &lt;class T&gt; class vector3D  {     T *x;     T *y;     T *z;     int meret; public:     void saveout(char* FileName);      vector3D(int Meret=0) :  x(new T[meret]), y(new T[Meret]), z(new T[Meret]), meret(Meret) {}      ~vector3D()  { delete [] x; delete [] y; delete [] z; } };   #endif // VECTORDDD_HPP_INCLUDED   implementation file (vectorddd.cpp):  #include "vectorddd.hpp"  template &lt;class T&gt; void vector3D&lt;T&gt;::saveout(char* FileName) {     int i=0;// I know this is stupid... but the emphasis is on the linking problem  }   And it just doesn't link together. I know I have to check .cpp files link and compile settings at properties->build options. And I don't find any problem, but is just write always the same:  In function `main': undefined reference to `vector3D&lt;int&gt;::saveout(char*)' ||=== Build finished: 1 errors, 0 warnings ===|   And if I put the .cpp files implementations into my .hpp file it works correctly. But this is not how codeblocks should 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.)
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?
11434
I recently had cause to work with some Visual Studio C++ projects with the usual Debug and Release configurations, but also 'Release All' and 'Debug All', which I had never seen before. It turns out the author of the projects has a single ALL.cpp which #includes all other .cpp files. The *All configurations just build this one ALL.cpp file. It is of course excluded from the regular configurations, and regular configurations don't build ALL.cpp I just wondered if this was a common practice? What benefits does it bring? (My first reaction was that it smelled bad.) What kinds of pitfalls are you likely to encounter with this? One I can think of is if you have anonymous namespaces in your .cpps, they're no longer 'private' to that cpp but now visible in other cpps as well? All the projects build DLLs, so having data in anonymous namespaces wouldn't be a good idea, right? But functions would be OK?
40378
I am working on a large C++ project in Visual Studio 2008, and there are a lot of files with unnecessary #include directives. Sometimes the #includes are just artifacts and everything will compile fine with them removed, and in other cases classes could be forward declared and the #include could be moved to the .cpp file.  Are there any good tools for detecting both of these cases?
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().
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?
37291
Does C++ support '' blocks?  What is the ?  What is the difference between C++'s RAII idiom and ?
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?
90693
VC++ makes functions which are implemented within the class declaration inline functions.  If I declare a class Foo as follows, then are the CONSTRUCTOR and DESTRUCTOR inline functions?  class Foo  {     int* p; public:     Foo() { p = new char[0x00100000]; }     ~Foo() { delete [] p; } };  {     Foo f;     (f); }
74152
You can structure a C++ program so that (almost) all the code resides in Header files. It essentially looks like a C# or Java program. However, you do need at least one .cpp file to pull in all the header files when compiling. Now I know some people would absolutely detest this idea. But I haven't found any convincing downsides of doing this. I can list some advantages:  [1] Faster compile times. All header files only get parsed once, because there is only one .cpp file. Also, one header file cannot be included more than once, otherwise you will get a build break. There are other ways of achieving faster compiles when using the alternate approach, but this is so simple.  [2] It avoids circular dependencies, by making them absolutely clear. If ClassA in ClassA.h has a circular dependency on ClassB in ClassB.h, I have to put a forward reference &amp; it sticks out. (Note that this is unlike C# &amp; Java where the compiler automatically resolves circular dependencies. This encourages bad coding practices IMO). Again, you can avoid circular dependencies if your code was in .cpp files, but in a real-world project, .cpp files tend to include random headers until you can't figure out who depends on whom.  Your thoughts?
17141
The code below compiles, but has different behavior for the char type than for the int types.  In particular     cout &lt;&lt; getIsTrue&lt; isX&lt;int8&gt;::ikIsX  &gt;() &lt;&lt; endl;    cout &lt;&lt; getIsTrue&lt; isX&lt;uint8&gt;::ikIsX  &gt;() &lt;&lt; endl;    cout &lt;&lt; getIsTrue&lt; isX&lt;char&gt;::ikIsX  &gt;() &lt;&lt; endl;   result in 3 instantiations of templates for three types: int8, uint8 and char. What gives?  The same is not true for ints: int and uint32 which result in the same template instantiation, and signed int another.  The reason seems to be that C++ sees char, signed char and unsigned char as three different types. Whereas int is the same as a signed int. Is this right or am I missing something?  #include &lt;iostream&gt;  using namespace std;  typedef   signed char       int8; typedef unsigned char      uint8; typedef   signed short      int16; typedef unsigned short     uint16; typedef   signed int        int32; typedef unsigned int       uint32; typedef   signed long long  int64; typedef unsigned long long uint64;  struct TrueType {}; struct FalseType {};  template &lt;typename T&gt; struct isX {    typedef typename T::ikIsX ikIsX; };   // This  int==int32 is ambiguous //template &lt;&gt;            struct isX&lt;int  &gt;    { typedef FalseType ikIsX; };  // Fails template &lt;&gt;            struct isX&lt;int32  &gt;  { typedef FalseType ikIsX; }; template &lt;&gt;            struct isX&lt;uint32 &gt;  { typedef FalseType ikIsX; };   // Whay isn't this ambiguous? char==int8 template &lt;&gt;            struct isX&lt;char  &gt;  { typedef FalseType ikIsX; }; template &lt;&gt;            struct isX&lt;int8  &gt;  { typedef FalseType ikIsX; }; template &lt;&gt;            struct isX&lt;uint8 &gt;  { typedef FalseType ikIsX; };   template &lt;typename T&gt; bool getIsTrue(); template &lt;&gt;           bool getIsTrue&lt;TrueType&gt;() { return true; } template &lt;&gt;           bool getIsTrue&lt;FalseType&gt;() { return false; }  int main(int, char **t ) {    cout &lt;&lt; sizeof(int8) &lt;&lt; endl;  // 1    cout &lt;&lt; sizeof(uint8) &lt;&lt; endl; // 1    cout &lt;&lt; sizeof(char) &lt;&lt; endl;  // 1     cout &lt;&lt; getIsTrue&lt; isX&lt;int8&gt;::ikIsX  &gt;() &lt;&lt; endl;    cout &lt;&lt; getIsTrue&lt; isX&lt;uint8&gt;::ikIsX  &gt;() &lt;&lt; endl;    cout &lt;&lt; getIsTrue&lt; isX&lt;char&gt;::ikIsX  &gt;() &lt;&lt; endl;     cout &lt;&lt; getIsTrue&lt; isX&lt;int32&gt;::ikIsX  &gt;() &lt;&lt; endl;    cout &lt;&lt; getIsTrue&lt; isX&lt;uint32&gt;::ikIsX  &gt;() &lt;&lt; endl;    cout &lt;&lt; getIsTrue&lt; isX&lt;int&gt;::ikIsX  &gt;() &lt;&lt; endl;  }   I'm using g++ 4.something
33770
I have a very large codebase (read: thousands of modules) that has code shared across numerous projects that all run on different operating systems with different C++ compilers. Needless to say, maintaining the build process can be quite a chore.   There are several places in the codebase where it would clean up the code substantially if only there were a way to make the pre-processor ignore certain #includes if the file didn't exist in the current folder. Does anyone know a way to achieve that?  Presently, we use an #ifdef around the #include in the shared file, with a second project-specific file that #defines whether or not the #include exists in the project. This works, but it's ugly. People often forget to properly update the definitions when they add or remove files from the project. I've contemplated writing a pre-build tool to keep this file up to date, but if there's a platform-independent way to do this with the preprocessor I'd much rather do it that way instead. Any ideas?
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.
8383
Again me with vectors. I hope I'm not too annoying. I have a struct like this :  struct monster  {     DWORD id;     int x;     int y;     int distance;     int HP; };   So I created a vector :  std::vector&lt;monster&gt; monsters;   But now I don't know how to search through the vector. I want to find an ID of the monster inside the vector.   DWORD monster = 0xFFFAAA; it = std::find(bot.monsters.begin(), bot.monsters.end(), currentMonster);   But obviously it doesn't work. I want to iterate only through the .id element of the struct, and I don't know how to do that. Help is greatly appreciated. Thanks !
86355
My team is responsible for the development of an API for a large system that we also write. We need to provide example code so that other developers using our API can learn how to use it. We have been documenting the code using the xml document comments. eg.  /// &lt;summary&gt;Summary here&lt;/summary&gt; /// &lt;example&gt;Here is an example  &lt;code&gt;example code here&lt;/code&gt; &lt;/example&gt; public void SomeFunction()    We then use Sandcastle and build the help files we need (chm and an online website).  It is quite embarrassing when the example code doesnt work, and this is usually because some functionality has changed or a simple error.  Has anyone ever done something like this, but also configured unit tests to run on the example code so that they are known to work during the build?
45104
I am programming with normal pointers, but I have heard about libraries like Boost that implement smart pointers. I have also seen that in Ogre3D rendering engine there is a deep use of shared pointers.  What exactly is the difference between the three, and should I stick on using just a type of them?
40269
I have a header file  x.h which is included by more than one *.c source files. This header file has some structure variables defined.  I have put multiple inclusion prevention guard at the beginning of the header file as:  #ifndef X_H #define X_H ... .. //header file declarations and definitons.   #endif//X_H   On building I get linker errors related to multiple definitions. I understand the problem.   Won't a multiple inclusion prevention guard at the top of header file as I have, prevent multiple inclusions of the header file x.h and thereby avoid multiple definitions of the variables that are there in x.h? #pragma once does not work on this particular compiler, so what is the solution?  Someone had posted  answer to a similar question. It doesn't seem to work for me. How does this solution work?