c++

c++ Exception Class Design

What is a good design for a set of exception classes? I see all sorts of stuff around about what exception classes should and shouldn't do, but not a simple design which is easy to use and extend that does those things. The exception classes shouldn't throw exceptions, since this could lead straight to the termination of the process wi...

Removing duplicate string from List (.NET 2.0!)

I'm having issues finding the most efficient way to remove duplicates from a list of strings (List). My current implementation is a dual foreach loop checking the instance count of each object being only 1, otherwise removing the second. I know there are MANY other questions out there, but they all the best solutions require above .n...

How to determine if a list is subset of another list?

What is efficient way to determine if a list is a subset of another list? Example: is_subset(List(1,2,3,4),List(2,3)) //Returns true is_subset(List(1,2,3,4),List(3,4,5)) //Returns false I am mostly looking for efficient algorithm and not too concern how the list is stored. It can be stored in array, link list or other data struct...

Howto make Java JNI KeyListener with C++

I'm trying to make a program like AutoHotKey, but with a graphical interface. I'm using java.awt.Robot Now I want to make the code for checking the state from a key (In AHK: getKeyState) Of course somthing like a KeyListener without having focus. I read already something with JNI and C++, but.... I can't find some information. Can someb...

polymorphic handles

hi, I have handles of different types inside a hierarchy. class Handle { common data } class HandleA : Handle { data specific to a } class HandleB : Handle { data specific to b } Most parts of the code only deal with handles. But some parts ( the "managers" for HandleA/HandleB ) need access to the data in the child classes. eg: void...

FindFirstFile and FindNextFile question

Output: The first file found is LOG_09.TXT Next file name is LOG_10.TXT Next file name is LOG_11.TXT Next fi (cut off word "file"?) Function: //Find last modified log file hFind = FindFirstFile("..\\..\\LOGS\\LOG*.TXT", &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { printf ("FindFirs...

Stack Frame Question: Java vs C++

Q1. In Java, all objects, arrays and class variables are stored on the heap? Is the same true for C++? Is data segment a part of Heap? What about the following code in C++? class MyClass{ private: static int counter; static int number; }; MyClass::number = 100; Q2. As far as my understanding goes, variab...

Change resize behavior in Qt layouts

I want my custom widgets to gain extra space when the dialog is resized. This was working when I only had a handful of widgets, but after adding several more columns of these same widgets and putting them in a QGridLayout, the extra space merely goes in as padding between the widgets. ...

Looking for an application GUI library for C++

I'm thinking about writing a very simple paint program. I would like a more advanced method of inputting data into my program like colors, thickness of the brush, etc. I would like to use a GUI library so I can program buttons and menus to make input easier. Any suggestions? (I'm running Visual C++ 2005 SP1) ...

boost::bind, boost::asio, boost::thread, and classes

sau_timer::sau_timer(int secs, timerparam f) : strnd(io), t(io, boost::posix_time::seconds(secs)) { assert(secs > 0); this->f = f; //t.async_wait(boost::bind(&sau_timer::exec, this, _1)); t.async_wait(strnd.wrap(boost::bind(&sau_timer::exec, this))); boost::thread thrd(&io,this); io.run(); //thrd(&sau_ti...

Call Tiny C Compiler from a C++ code

I'm trying to compile a C code in a file from a program in C++. When I run my program it call the Tiny C Compiler and generate a dll from the compilation of c code. I tried to do it by a lot of ways but I couldn't. Did anyone already do something like this? Thanks ...

Programs run in 2 seconds on my machine but 15 seconds on others.

I have two programs written in C++ that use Winsock. They both accept TCP connections and one sends data the other receives data. They are compiled in Visual Studio 2008. I also have a program written in C# that connects to both C++ programs and forwards the packets it receives from one and sends them to the other. In the process it coun...

Type limitation in loop variables in Java, C and C++

Why Java, C and C++ (maybe other languages also) do not allow more than one type on for-loop variables? For example: for (int i = 0; i < 15; i++) in this case we have a loop variable i, which is the loop counter. But I may want to have another variable which scope is limited to the loop, not to each iteration. For example: for (int ...

Debugging/tracing inside a shared library during runtime?

Hello everyone, I'm trying to understand how a certain library works. I've compiled it with my added prinfts and everything is great. Now I want to stop the example program during runtime to look at the call stack, but I can't quite figure out how to do it with gdb. The function I want to break on, is inside a shared library. I've revie...

Measuring text width in Qt

Using the Qt framework, how do I measure the width (in pixels) of a piece of text rendered with a given font/style? ...

How to update a printed message in terminal without reprinting (Linux)

I want to make a progress bar for my terminal application that would work something like: [XXXXXXX ] which would give a visual indication of how much time there is left before the process completes. I know I can do something like printing more and more X's by adding them to the string and then simply printf, but that would lo...

How to place objects that seem not be comparable in a C++ std::set?

Suppose I want to put objects that identify a server into a stl set. Then I would have to make sure that I also implement operator< for these objects otherwise I would run into a compiler error: struct ServerID { std::string name; // name of the server int port; }; std::set<ServerID> servers; // compiler error, no operator< defined...

Authenticating users using Active Directory in Client-Server Application

I've been asked to provide support for authenticating users against an Active Directory in our existing client server application. At the moment a user supplies a user name and password from a client machine, passed over the wire (encrypted) to our server process and matched against a user name/password stored in a database. Initiall...

What are some reasons not to statically link to the VC CRT?

I'm finding that with dynamic linking, even with SxS, Windows Update will come along and stomp on a version of the VC8 CRT (for example it has a security flaw) and then my app will fail to run with older versions. What are some of the important reasons to stay with the dynamic linking with VC CRT, other than increasing the size of your ...

How to take these parameters the same way this function does?

For example: - (BOOL)compare:(NSDecimal)leftOperand greaterThan:(NSDecimal)rightOperand { NSComparisonResult result = NSDecimalCompare(&leftOperand, &rightOperand); // rest not important } like you can see, the method just receives these two types of NSDecimal, leftOperand and rightOperand. Then it passes them on to a C API fu...