c++

Function overloading with polymorphic templates

Why is the following code not compiling and how would it be possible to use the function from the base class? template<typename K> struct Base { K foo() { return (K)0; } }; template<typename K> struct Extension : public Base<K> { K foo(int a) { return (K)a; } }; int main() { Extension<float> e; e.foo(); return 0; }...

Box Based 3D terrain generation algorthms? (procedural generation)

I have been looking at this game called Minecraft and was intrigued by how it can dynamically generate random maps that look and feel right. What types of algorithms are used to generate terrains based on cubes like this? Thanks ...

Implementing a tree in C++

Hello, I'm trying to implement a generic hierarchical tree for C++ Linux project. I haven't been able to find any standard library tree containers, though. Do any exist? Thanks in advance, Tim ...

Optimizing this OpenGL rendering algorithm

My game draws a series of cubes from a VBO, and just translates to the cube's position each time: ... SetCameraMatrix(); SetFrustum(); //start vbo rendering glEnableClientState(GL_VERTEX_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 1); glVertexPointer(3, GL_FLOAT, 0, 0); glColor3f(1,0.5,0); for(int i = 0...

Is there any way to use a variable in a lambda which isn't in the current scope?

Basically, I want to know if something like the below is possible? If this isn't possible is there any way to fake it? #include <iostream> using namespace std; template<typename Functor> void foo(Functor func) { auto test = [](Functor f){ int i = 5; f(); }; test(func); } int main() { foo([](){ cout << i << endl;}); } ...

using an external variable in C++ in a shared library - creating a shared library (dll) using MinGW g++

I am trying to create a shared library on Windows. I am able to create this shared library on linux but on windows I get linker errors. I am using the MinGW G++ 4.5 compiler. I will first present the source code to the example on linux , and then present the file which I tried to change on windows. /home/nxd/Progs/C++/shared-lib>cat lib...

C++: how to debug a "General Protection Exception"?

hi, i've faced an unhandled exception of "General Protection Exception". while the program runs but there is no output. i wanted to know what are general efforts i can do to debug such an Exception? thanks ...

Can you mix free and constructor in C++?

Possible Duplicate: Is there any danger in calling free() or delete instead of delete[]? I was reading this question: http://stackoverflow.com/questions/184537/in-what-cases-do-i-use-malloc-vs-new/ Someone raised that one reason to use malloc was if you were going to use free. I was wondering: Is it valid to mix a free call ...

Segmentation fault c++ templates

I wrote my first ever C++ template code on expandable array and I am getting a segmentation fault! After an hour of debugging I have realized that I need help. Something is wrong with the constructor or the destructor I think but not sure. The code is on pastie ready to be compiled. http://pastie.org/1150617 /* Expandable array in C++ ...

How to get right row height in Qt for QTableView object?

From this screenshot you can see a lot of space inside the rows: I've used these functions to get resizing: resizeRowsToContents(); resizeColumnsToContents(); How can I get a better fit for cells/rows sizes? ...

Registering python callables in C++ classes

I'm writing a program in python which should be able to pass "callables" which are registered in a C++ class. So far I've written the following code: C++: class MyClass { ... public: register_callback(boost::function<void (int)> fun); }; Python/C API: class_<MyClass, boost::shared_ptr<MyClass>, boost::noncopyable>("MyClass", no_...

C/C++ Determine Whether Files have been completely written

I have a directory (DIR_A) to dump from Server A to Server B which is expected to take a few weeks. DIR_A has the normal tree structure i.e. a directory could have subfolders or files, etc Aim: As DIR_A is being dumped to server B, I will have to go through DIR_A and search for certain files within it (do not know the exact name of ...

Debugging "Multiple-step OLE DB operation generated errors."

This is kinda a general question, looking for as much info as possible. I have code which generates this error (the define is DB_E_ERRORSOCCURRED), and I'm looking for the best methods to debug it (eg: figure out what the particular errors were). I'm aware that there are some other SO questions related this this error (eg: here, here, he...

C++ valgrind possible leaks on STL string

Hi, I do not see the reason of the leak below. #include <iostream> #include <cstdlib> int fail(const std::string str) { std::cerr<< str << std::endl; exit(1); } const std::string usage() { std::string a = "a"; return a; } int main() { fail(usage()); return 0; } Valgrind says: ==7238== 14 bytes in 1 bloc...

professional-quality charting library for c++

Hi, I'm writing an application in c++/MFC and there's a need to create good-quality charts (bar charts, line graphs, maybe even some custom graphics...). As an additional feature, I need to be able to export my graphs in MS Office Graph/Drawing binary file format (so that people can see them in Excel, bitmaps and metafiles just don't c...

monitoring a file for changes

I'm trying to achieve tail-like functionality in my Visual Studio 2008 C++ application. (i.e. show in real-time the changes to a file not owned by my process.) /// name of the file to tail std::string file_name_; /// position of the last-known end of the file std::ios::streampos file_end_; // start by getting the position of the end o...

Can I Have Polymorphic Containers With Value Semantics in C++0x?

This is a sequel to a related post which asked the eternal question: Can I have polymorphic containers with value semantics in C++? The question was asked slightly incorrectly. It should have been more like: Can I have STL containers of a base type stored by-value in which the elements exhibit polymorphic behavior? If you ar...

C++: include multiple header files with same name from different namespaces

How do you solve created by including a header file with the same name as another header file already indirectly included as a result of another include? For instance: // src/blah/a.hpp #ifndef A_HPP #define A_HPP namspace blah { class A { } } #endif // src/blah/b.hpp #ifndef B_HPP #define B_HPP #includes "a.hpp" namspace blah {...

HTTP requests from app disappearing between sender's network/proxy and our web host

I don't have very much information to work with here, yet. Our app sends an HTTP query to our server, and in all the cases we've used until now it has worked fine. But for one client, whose network goes through a proxy, their logs indicate that the request goes out successfully, but no reply ever returns, and our web server shows nothi...

Send Events to a Windows Service from Kernel Mode

I am writing a piece of software that consists of a kernel mode driver and a user mode Windows service. The kernel driver needs to notify the service of different events and information, which the service will then process. My question is this: What is the best way to set up this communication? I know it is possible to get a message ...