c++

What tools exist for comparing C++ code to coding guidelines?

There exist tools for comparing code against a custom specified set of coding guidelines/standards for a variety of languages (rather than pure static analysis for common defects). Examples include FxCop for .Net code and CheckStyle for Java, but I was wondering what examples people know of in the C++ world. An existing question was as...

what is a domain error

in c++, <stdexcept> has a base class for 'domain errors', std::domain_error. i don't understand under what circumstances i should throw a domain error in my code. all of the other exception base classes are pretty self explanatory. i'm pretty sure that std::domain_error has nothing to do with internet domain names, per se, so please e...

Correct value for hWnd parameter of BeginPaint?

I am trying to make a Visual C++ 2008 program that plots some data in a Window. I have read from various places the correct way to do this is to override WndProc. So I made a Windows Forms Application in Visual C++ 2008 Express Edition, and I added this code to Form1.h, but it won't compile: public: [System::Security::Permissions...

Best way to convert Delphi code to C++?

I have an application written in Delphi that compiles in Delphi 2007. I think it was originally written in Delphi 7. Anyway, I need to convert all the core non-GUI code into C++ because I want to release a Mac version of the software. What is the best way to do this? Any shortcuts I can take to speed up the process? EDIT: The code com...

How to figure out where to load program data from?

I've got a project written in C++ (with glibmm helping), and I'm using autotools to manage it. The question I have to ask is "HOW ON EARTH DO I FIGURE OUT WHERE TO LOAD STUFF FROM?". While I can find all the guides I want to on autotools, none answer this question. For example, maps go in $DATADIR/maps (usually /usr/[local/]share/myprog...

C++ best way to define cross-file constants

Hi, I am working on a game and have an interesting question. I have some game-wide constant values that I want to implement in one file. Right now I have something like this: constants.cpp extern const int BEGINNING_HEALTH = 10; extern const int BEGINNING_MANA = 5; constants.hpp extern const int BEGINNING_HEALTH; extern const int B...

Are threading issues for C/C++ "system level programmers" significantly different from those faced by Java programmers?

I'm looking for a development job and see that many listings specify that the developers must be versed in multithreading. This appears both for Java job listings, and for C++ listings that involve "system programming" on UNIX. In the past few years I have been working with Java and using its various synchronization mechanisms. In the...

Why doesn't glCopyTexSubImage2D copy my square correctly?

here is the output: http://i43.tinypic.com/9a5zyx.png if things were working the way i wanted, the colors in the left square would match the colors in the right square. thanks for any help regarding the subject #include <gl/glfw.h> const char* title="test"; GLuint img; unsigned int w=64,h=64; int screenwidth,screenheight; void enable2...

Favorite Valgrind Options

I usually use this: valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./mycode But not sure if on one hand it checks everything, on the other hand too verbose. What's your favorite option? ...

Remove the common entities from two vector?

say I have vector<class1a>,vector<class1b> how to remove the common entities from both of them I have defined ==operator for the class1 objects class1a,class1b ...

What is __unwind$ in a linker map file

For VS2008 (C++) generated linker map files, what does the symbol "__unwind$" mean? I have a good chunk of them in the linker map file for my app. I have a log which says a crash happens at a particular offset say 'x'. When I look at the linker map for this offset, I find this __unwind$41357 corresponding to the offset. Also generally ...

Returning a pointer to a vector element in c++.

I have a vector of myObjects in global scope. I have a method which uses a std::vector<myObject>::const_iterator to traverse the vector, and doing some comparisons to find a specific element. Once I have found the required element, I want to be able to return a pointer to it (the vector exists in global scope). If I return &iterator, am...

WASAPI prevents Windows automatic suspend?

First time poster, be gentle ;-) I'm writing an audio app (in C++) which runs as a Windows service, uses WASAPI to take samples from the line in jack, and does some processing on it. Something I've noticed is that when my app is "recording", Windows won't automatically suspend or hibernate. I've registered for power event notificatio...

g++ undefined reference to constructor

Hi, I'm compiling and linking a cpp file against a pre-compiled library, and I'm getting an "undefined reference" error. Firstly, this is the command (the library in question is quicknet3, the program I'm compiling is trapper): g++ -w -g -I. -g -O3 -pipe -Wall -I/home/install/x86_64/include/quicknet3 -L/home/install/x86_64/lib -lqui...

How to embed Windows Form in unmanaged ATL GUI?

I have a Windows form user control that is made COM visible. Now I want to embed that control into an ATL dialog GUI. The ATL project (unmanaged C++) shall only get the progID of the winform and dynamically create and embed it at runtime. Is this possible and if so, how do I do it? ...

Overloading Arithmetic Operators

The assignment operator can be declared as T& operator= (const t&); in a class, but the arithmetic operators cannot be defined that way. It has to be friend function. I don't understand why? Can you please explain ? ...

How to implement a natural sort algorithm in c++?

I'm sorting strings that are comprised of text and numbers. I want the sort to sort the number parts as numbers, not alphanumeric. For example I want: abc1def, ..., abc9def, abc10def instead of: abc10def, abc1def, ..., abc9def Does anyone know an algorithm for this (in particular in c++) Thanks ...

Why do I need to use typedef typename in g++ but not VS?

It had been a while since GCC caught me with this one, but it just happened today. But I've never understood why GCC requires typedef typename within templates, while VS and I guess ICC don't. Is the typedef typename thing a "bug" or an overstrict standard, or something that is left up to the compiler writers? For those who don't know w...

C/C++ Windows traffic blocker

I want to develop a bandwidth allocator to a network which will be behind my machine. Now, I've read about NDIS but I am not sure whether the network traffic that is neither originating from my machine nor is destined for my machine will enter my TCP/IP stack, so that I can block/unblock packets via NDIS on a windows machine. ...

Does GetSystemInfo give you the total number of virtual CPUs (i.e. hyper-threaded)?

GetSystemInfo will give you the number of physical CPUs / cores, but I would like to know the total number of virtual CPUs. I.e. on the new Nahelam chips, they have 4 cores, but appear as 8 cpus. If GetSystemInfo doesn't give this information, what API do I need (I've seen a function for getting number of logical processors, but it is V...