c++

When using QT in VS2008, IntelliSense does not work properly

I use QT 4.4.2 in Visual Studio 2008. When I am writing code, IntelliSense seems to die - it does not show any methods or data members in QT objects such as QPushButton, does not see the QObject::connect static method, etc. Is it a typical situation or did I do something wrong while installing the library? ...

How can I create directory tree in C++/Linux?

I want an easy way to create multiple directories in C++/Linux. For example I want to save a file lola.file in the directory: /tmp/a/b/c but if the directories are not there I want them to be created automagically. A working example would be perfect. ...

C++ Parser/Model for Java

I was wondering if anyone knows of existing C++ parsers/code models that can be used programmatically in Java. I'm looking for something similar to the Eclipse CDT that can be used as a library from Java (and that does not rely upon Eclipse). Thanks in advance. ...

Avoiding too many configurations for a Visual Studio project

I'm currently porting a large Linux project to Visual Studio. The project depends on a number of third-party libraries (Python, MPI, etc.) as well as a couple of in-house ones. But it can also be built without these libraries, or with only a few of them. So I don't want to create a different configuration for each possible combination, e...

Best Practice for Scoped Reference Idiom?

I just got burned by a bug that is partially due to my lack of understanding, and partially due to what I think is suboptimal design in our codebase. I'm curious as to how my 5-minute solution can be improved. We're using ref-counted objects, where we have AddRef() and Release() on objects of these classes. One particular object is de...

Blob ...how to write non-recursively

I have written the following program, using recursion, but I can't figure out how to write it non-recursively. Every time I run my non-recursive version the numbers are way off. Any suggestions on how to write the following method without recursion? int countCells(color grid[ROWS][COLS], int r, int c) { if (r < 0 || r >= ROWS || c < 0 ...

Trouble compiling dll that accesses another dll.

So, I have an interesting issue. I am working with a proprietary set of dlls that I ,obviously, don't have the source for. The goal is to write an intermediate dll that groups together a large series of funnction calls from the proprietary dlls. The problem I am having, when compiling with g++, is that I get errors for the original dl...

boost::asio::ip::tcp::resolver::resolve() blocks forever...

I'm trying to create something similar as this code found at the boost.asio examples. socket.h: class some_class { private: ... boost::asio::io_service io_service; public: some_class() { /* This stuff isn't used in the example... ...but it doesn't change anything... */ io_ser...

Pushing vector of vectors

Is there anything wrong with pushing back a vector of vectors? like typedef vector<Point> Polygon; vector<Polygon> polys; polys.push_back(some_poly); All the elements in some_poly will be copied right? I have a bug in my code and I can't seem to figure out what's wrong with it. ...

Splitting an STL vector

Let's say I have a (convex) polygon with vertices 0..n-1. I want to split this polygon in half, say, between verticies i and j. Vertices i and j should appear in both polygons. As far as I can tell, there are only two cases. One where i < j, or when i > j. i is never equal to j (nor are they ever adjacent). I'm storing my vertices lik...

How do I create an array in C++ which is on the heap instead of the stack?

I have a very large array which must be 262144 elements in length (and potentially much larger in future). I have tried allocating the array on the stack like so: #define SIZE 262144 int myArray[SIZE]; However, it appears that when I try and add elements past a certain point, the values are different when I try to access them. I under...

How to print an entire istream to standard out and string

How do you print an istream variable to standard out. [EDIT] I am trying to debug a scenario wherein I need to ouput an istream to a log file ...

MSVC++: Strangeness with unsigned ints and overflow

I've got the following code: #include <iostream> using namespace std; int main(int argc, char *argv[]) { string a = "a"; for(unsigned int i=a.length()-1; i+1 >= 1; --i) { if(i >= a.length()) { cerr << (signed int)i << "?" << endl; return 0; } } } If I compile in MSVC with full optimizations...

SDL/C++ OpenGL Program, how do I stop SDL from catching SIGINT

Hi I am using SDL for an OpenGL application, running on Linux. My problem is that SDL is catching SIGINT and ignoring it. This is a pain because I am developing through a screen session, and I can't kill the running program with CTRL-C (the program the computer is running on is connected to a projector and has no input devices). Is the...

stdafx.h: When do I need it?

I see so much code including stdafx.h. Say, I do not want pre-compiled headers. And I will include all the required system headers myself manually. In that case is there any other good reason I should be aware of where I require stdafx.h? ...

Seg fault after is item pushed onto STL container

typedef struct temp { int a,b; char *c; temp(){ c = (char*)malloc(10);}; ~temp(){free(c);}; }temp; int main() { temp a; list<temp> l1; l1.push_back(a); l1.clear(); return 0; } giving segmentation fault. ...

How to do fsync on an ofstream?

I want to make sure that an ofstream has been written to the disk device. What's the portable way (portable on POSIX systems) of doing this? Does that solve the problem if I open the file separately in read-only append mode to get a file descriptor and call fsync with it? Like this: ofstream out(filename); /* ... write content into ...

Memory management while loading huge XML files

We have an application which imports objects from an XML. The XML is around 15 GB. The application invariably starts running out of memory. We tried to free memory in between operations but this has lead to degrading performance. i.e it takes more time to complete the import operation. The CPU utilization reaches 100% The application is...

Your opinion on declaring constants inside methods...?

Hi there, A developer in a team I'm supervising prefers declaring variables as constants in his tests, e.g. const int someValue = 1; (rather than just int someValue = 1;). When I saw this I found it a bit odd and questioned what he'd done. His argument is that this is sensible for the purposes of this test - because the value he's assi...

Speed of virtual call in C# vs C++

I seem to recall reading somewhere that the cost of a virtual call in C# is not as high, relatively speaking, as in C++. Is this true? If so - why? ...