c++

Best Data Structure for Genetic Algorithm in C++ ?

Hello, i need to implement a genetic algorithm customized for my problem (college project), and the first version had it coded as an matrix of short ( bits per chromosome x size of population). That was a bad design, since i am declaring a short but only using the "0" and "1" values... but it was just a prototype and it worked as intend...

Broken std::map visualiser in VS2005

I'm using the Intel compiler and visual studio and I can't seem to debug values that are in maps. I get a quick preview which shows the size of the map but the elements only show up as "(error)", I'll illustrate with a quick example, i've generated a map with a single entry myMapVariable[6]=1; if I mouse over I get this "myMapVariable ...

Debug Assertion Failed ... _BLOCK_TYPE_IS_VALID (pHead ...

I am getting this error message while trying to do the following #include <vector> #include <algorithm> using namespace std; class NN { public: NN(const int numLayers,const int *lSz,const int AFT,const int OAF,const double initWtMag,const int UEW,const double *extInitWt); double sse; bool operator < (const NN &net) const {r...

Handling binary dependencies across platforms

I've got a C++ project where we have loads and loads of dependencies. The project should work on Linux and Windows, so we've ported it to CMake. Most dependencies are now included right into the source tree and build alongside the project, so there are no problems with those. However, we have one binary which depends on Fortran code etc...

Testing a gSOAP server

In a normal client/server design, the client can execute functions implemented on the server-side. Is it possible to test a gSOAP server by connecting an extra client to it? ...

STL maps with user-defined objects

I'm wondering why I can't use STL maps with user-defined classes. When I compile the code below, I get this cryptic error message. What does it mean? Also, why is it only happening with user-defined types? (primitive types are okay when it is used for the key) C:\MinGW\bin..\lib\gcc\mingw32\3.4.5........\include\c++\3.4.5\bits\stl_f...

What does a "true;" or "10;" statement mean in C++ and how can it be used?

In C++ one can write any of the following statements: 10; true; someConstant; //if this is really an integer constant or something like int result = obtainResult(); result; // looks totally useless The latter can be used to suppress a compiler warning "A variable is initialized but not referenced" (C4189 in VC++) if a macro that is...

How to do alpha blend fast?

I am using c++ , I want to do alpha blend using the following code. #define CLAMPTOBYTE(color) if((color) & (~255)) {color = (BYTE)((-(color)) >> 31);}else{color = (BYTE)(color);} #define GET_BYTE(accessPixel, x, y, scanline, bpp)\ ((BYTE*)((accessPixel) + (y) * (scanline) + (x) * (bpp))) for (int y = top ; y < bottom; ++y) { BYTE...

Handling different datatypes in a single structure

I need to send some information on a VxWorks message queue. The information to be sent is decided at runtime and may be of different data types. I am using a structure for this - struct structData { char m_chType; // variable to indicate the data type - long, float or string long m_lData; // variable to hold long value float ...

Windows not drawing above OpenGL windows

I have an app with an OpenGL window as a child window of the main window. When I display a dialog box above the OpenGL window, it doesn't get drawn. It's like it's not getting WM_PAINT messages. If I can guess the title bar position of the dialog box, I can drag it and it's still responsive. I realise this might be a vague question, b...

Capturing syscall stdout without writing to file in C/C++

I want to read the std output of a system call into a C/C++ string. Can I do this without using a temp file? Perl //without file io $output = `echo hello`; C++ //with file io system ("echo hello > tmp"); std::fstream file ("tmp"); std::string s; file >> s; ...

Is anybody using the named boolean operators?

Or are we all sticking to our taught "&&, ||, !" way? Any thoughts in why we should use one or the other? I'm just wondering because several answers state thate code should be as natural as possible, but I haven't seen a lot of code with "and, or, not" while this is more natural. ...

is it safe to recv passing in 0 to detect a socket error?

For a TCP blocking socket, is it safe to call: if(SOCKET_ERROR != recv(s, NULL, 0, 0)) //... to detect errors? I thought it was safe, then I had a situation on a computer that it was hanging on this statement. (was with an ssl socket if that matters). I also tried passing in the MSG_PEEK flag with a buffer specified but I also had...

Anyone managed to get iphone-dev compiled for FW3 under Leopard?

Now that firmware 3 is out, has anyone managed to get the iphone-dev toolchain compiled under Leopard at all? I suspect it's a little early for such things perhaps but I appear to be having quite a few problems getting the toolchain compiled (llvm-gcc specifically). ...

How can i query the number of cores avaiable?

Possible Duplicate: Programmatically find the number of cores on a machine I have a 3d game, and I am rebuilding its engine from scratch. The new incarnation uses multi-threading to take advantage of multiple cores. Does anyone know of a cross-platform(linux/win/mac) solution for querying the number of available cores? ...

Painting on top of video in a Qt Widget

I am developing a Qt application that can play the videos and shows some scrolling bar along the way. The window size MUST Not exceed the limit of 720px in height and 1280 in width. I use MPlayer as a slave process and pass it the winId() of the QWidget and it renders the video in it. Now I want another widget on top of this video widget...

Prompt with editable default in c++?

Is is possible (without external library such as boost) to prompt for input from the user, like using cin, but with a default choice that is editable by the user (without a GUI)? For example, the program will say: Give your input: default and the user can press enter to use "default" or press 1 then enter to get "default1", etc. ED...

"Generic" iterator in c++

I have: void add_all_msgs(std::deque<Message>::iterator &iter); How can I make that function "generic", so it can take any kind of inputiterators ? I don't really care if it's iterating a deque,a vector or something else, as long as the iterator is iterating Message's. - is this at all straight forward possible in c++ ? ...

C++ RAII not working??

I'm just getting started with RAII in C++ and set up a little test case. Either my code is deeply confused, or RAII is not working! (I guess it is the former). If I run: #include <exception> #include <iostream> class A { public: A(int i) { i_ = i; std::cout << "A " << i_ << " constructed" << std::endl; } ~A() { std::cout << "A ...

Is there a simpler Windows C++ Subversion API or an example .vcproj for minimal_client.c?

Following on the tails of my previous (answered) question... SharpSvn makes calling the Subversion client API simple: SvnClient client = new SvnClient(); client.Authentication.DefaultCredentials = new NetworkCredential(username, password); client.CheckOut(new Uri("http://xxx.yyy.zzz.aaa/svn/repository"), workingCopyDir); On the other...