c++

Passing Exception Types down through a menu.

So I've come across this problem and I can't seem to solve it. Basically I've got a menu of tests, it can be of arbitrary depth, it's just a way of organizing tests and at the lowest level has specific test-cases. As it stands right now everything seems to work, however I'd like to implement a system where you can specify an exception ...

New not allocating enough memory?

Well, I'm taking packets straight off the wire and extracting TCP streams from them. In the short, this means stripping off the various headers (eg, eth->IP->TCP->stream data). In the function that is called when I've finally gotten through all the headers, I am experiencing a strange error. /*Meta is a pointer to the IP heade...

foreach algorithm in C++

Is there a way to have a return value from the function that I pass to foreach. For ex: I have, void myfunction (int i) { cout << " " << i; } vector<int> myvector; myvector.push_back(10); for_each (myvector.begin(), myvector.end(), myfunction); Lets say, I want to count the number of elements in the vector using some rule, ...

Anyone uses boost::multiindex as a one-table database?

I need to maintain a 200 entries, 12 column table at extremely high speed, can I simply use boost multiindex to cutoff the sql overhead? Has anyone ever tried to do this? What are the cons and pros of such a solution? thanks ...

Benefits of opening a file for read and write

Can anyone point me to some discussion covering the pro's and con's of opening a file for read and write as opposed to (for example) opening a file for read, closing it and then reopening for write. I've tried searching for in-depth information without joy. Many thanks ...

MSBuild and C++

If I am content to not support incremental builds, and to code everything via Exec tasks, is there any reason I can't build C++ binaries with an MSBuild script? I know VS 2010 will actually have support for a true MSBuild based project file, but what I'm trying to do is to integrate an old embedded VC++ 4.0 workspace into an overall lar...

help with template mergesort function

error C2065:'temp' : undeclared identifier i know that for "temp" i need to declare the type that the array is like int temp[] but what if i don't know what it is.. it could be int or string or double.. how can i create a temp array not specifying what it should be Here is my code: template<class T> void Mergesort(T& a, int first...

Given a start and end point, and a distance, calculate a point along a line

Looking for the quickest way to calculate a point that lies on a line a given distance away from the end point of the line: void calculate_line_point(int x1, int y1, int x2, int y2, int distance, int *px, int *py) { //calculate a point on the line x1-y1 to x2-y2 that is distance from x2-y2 *px = ??? *py = ??? } Thanks fo...

Is there a better way to create this game loop? (C++/Windows)

I'm working on a Windows game, and I have this: bool game_cont; LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_QUIT: case WM_CLOSE: case WM_DESTROY: game_cont = false; break; } return DefWindowProc(hWnd, msg, wParam, lParam); } int WINAPI WinMain(/*lots of paramete...

QGraphicsView/Scene - multithreading nightmare

Am I correct in thinking that the QGraphics* classes are not thread-safe? I am porting an old app to Qt and in the process attempting to make it multi-threaded too. I looked at the update code and I see no locks whatsoever. I started off right, all my processing is done in a set of worker threads so that the GUI does not have to block. ...

What is the performance penalty of operator overloading STL

I like STL a lot. It makes coding algorithms very convenient since it provides you will all the primitives like parition, find, binary_search, iterators, priority_queue etc. Plus you dont have to worry about memory leaks at all. My only concern is the performance penalty of operator overloading that is necessary to get STL working. For ...

Are there well-defined size limits in FormatMessage?

I am having a problem when arguments passed to FormatMessage are too long. void testMessage(UINT id, ...) { va_list argList; va_start(argList, id); LPTSTR buff = NULL; const char* str = "The following value is invalid: %1"; DWORD success = FormatMessage(FORMAT_MESSAGE_FROM_STRING|FORMAT_MESSAGE_ALLOCATE_BUFFER, ...

const attribute in class, should be public or protected ??

Hi All, I have some attributes which are const, so should these attributes be made public or protected ? I was in support of protected because it is used by some of the derived classes, but my friend argued that since it is const, it doesnt make any difference even if it is public, which also makes some sense. But, as I learnt cpp, I ...

Convert single char to int

How can I convert char a[0] into int b[0] where b is a empty dynamically allocated int array I have tried char a[] = "4x^0"; int *b; b = new int[10]; char temp = a[0]; int temp2 = temp - 0; b[0] = temp2; I want 4 but it gives me ascii value 52 Also doing a[0] = aoti(temp); gives me error: invalid conversion from ‘char’ to ‘cons...

Strange error with hardware picking in directx

Hi all, i am trying to get pickigng working in directx 9 and i am having some trouble. it works fine when i am rendering my mesh in software however i do get errors when rendering with a shader. i can be off of a mesh but it still detects it as a hit (see image for more detail) i am stopping animation controllers and updating frame mat...

I have a c++ exersise that I have done...

It's a c++ exercise, I will copy and paste it below with the code that I came up with. The code seems to be getting stuck in a loop and the texts scrolls across my screen so fast that I have no idea what to do and its hard to stop it. I have no idea where I'm going wrong so if someone could look at it for me please I'd be really greatful...

c++ server htons to java ntohs client conversion

Hi I am creating a small TFTP client server app where server is developed using c++ and client using java. Here i am sending "block count" value using htons conversion. But i am not able to convert it back to its original value at client. for example if am sending block count ntohs(01) (2 bytes) from se...

Input class - appropriate use of friend?

After seeing one of my classes grow far too large, I decided to separate out its input handling into another class. However, in order for the input to actually do anything to the object, it needs access to its private members. I could obviously provide public functions in the main class that input class could use, but since coupling is ...

C tokenize polynomial coefficients

I'm trying to put the coefficients of polynomials from a char array into an int array I have this: char string[] = "-4x^0 + x^1 + 4x^3 - 3x^4"; and can tokenize it by the space into -4x^0 x^1 4x^3 3x^4 So I am trying to get: -4, 1, 4, 3 into an int array int *coefficient; coefficient = new int[counter]; p = strtok(copy, " +"); ...

Decent SMTP client in C++

Hi, I'd like to have a decent SMTP client-side library in C++ with permissive license (LGPL, BSD, MIT-X, ...). It must have at least rfc821 and rfc2487 conformity and preferably rfc3207 conformity. I have found some that have not met all the requirements: Poco SMTP DataReel SMTP vmime If you have any, please kindly share. Thank you...