c++

How do I resolve link errors that appear in Objective-C++ but not Objective-C?

Hi guys, I'm converting my App Delegate file from .m to .mm (Objective-C to Objective-C++) so that I can access a third-party library written in Objective-C++. In Objective-C, my app delegate builds and runs fine. But when I change the extension, the project builds and I get link errors, all of which are missing symbols from a static li...

Convert boost::uuid to char*

I am looking to convert a boost::uuid to a const char*. What is the correct syntax for the conversion? ...

Weird Error in C++ Program: Removing Printout Breaks Program

This is a very strange problem... removing the cout in the function below causes it to stop printing the correct/expected results and printing garbage values. (i.e. it still RUNS the data it outputs, though, is wrong). Any ideas? bool extract_tension(std::vector<double> &interfacial_tension_trap, std::vector<double> &interfacial...

Invalidating loop bounds

I've recently inherited a project primarily done in C++, so this is my first real exposure to it. I'm wondering if I may have a problem erasing a vector's elements from within a loop bounded by the vector's begin() and end(). Here's (essentially) what I've been trying to do: for (vector<double>::iterator i = distance.begin(); i < dista...

In which cases is alloca() useful?

Why would you ever want to use alloca() when you could always allocate a fixed size buffer on the stack large enough to fit all uses? This is not a rhetorical question... ...

Boost Python (Suse and Ubuntu)

Hi, I created a simple .so library containing definition of a C++ class which should be accessed from Python and used for this purpose boost python library. When I'm testing this library using x64 Ubuntu it is enough to set LD_LIBRARY_PATH with the path to boost libs before running python. It doesn't work, however, when I'm using x64 Sus...

Using Boost.Program_options in modular program

The code I use consists of set of modules, compiled to individual libraries. Libraries in turn, are linked in different combinations to build different binaries. So for, it's pretty ordinal. Different modules use different command line arguments and I want to use Boost.Program_options for parsing. Since the set of command line argu...

C++ Templates and Subclasses?

So, I'm learning C++, and I've run into something which I know how to do in Java, but not in C++ :). I have a template for a container object, which is defined as such: template <class T> class Container { vector<T> contained; public: void add(T givenObject) { this->contained.push_back(givenObject); } T g...

How do I remove the smallest and largest element in an array in a manner that's appropriate to C++?

Let's say I have an array of ints and I want to call a function to remove the smallest and largest values. By remove I mean that if my initial array was 7 elements in length, the new array has 5 elements. The order of the remaining elements does not matter. I've come up with some ways to do it, but I'm not sure which one is the C++ "way"...

Windows: Check if a window has focus?

Possible Duplicate: How can I tell if a Window has focus? (Win32 API) I have a HWND in a C++ windows app. How can I tell if it has focus or not? UPDATE Looks like this is a dupe. Sorry. ...

Building a project with Boost dynamic libraries disabled

I'm trying to build the open source project VMWare open view client. The problem I'm having is I can build it following their instructions however my build does not include all the depedencies and thus when I go to deploy it there is a failure saying missing libboost_signals-gcc41-1_34_1.so.1.34.1. According to their forums someone sug...

GetTickCount function

Hi all, I have a question regarding GetTickCount function, I have two calls to this function in my code with several commands between them and the function in both calls returns same count. i.e. var1 = GetTickCount(); code : : var2 = GetTickCount(); var1 and var2 has same values in it. can someone help? ...

Why do array[n] and array[x] where x=n return different values?

Does anyone know what may cause the read-back values of array[n] and array[x] (x=n) different from each other? EDIT: Following is a compilable code to illustrate the problem I encountered. If you run the following code, you won't see any problem. I am just using it to describe the problem I saw in my original program which is a simulato...

How to set a CMFCPropertyListCtrl's column width?

I'm adding properties to an object of type CMFCPropertyGridCtrl like this: myPropertyListCtrl.AddProperty( new CMFCPropertyGridProperty( _T("Name"), foo.GetName()) ); The result is that only the second column is visible but not the first that should contain "Name". I found CMFCPropertyGridCtrl::GetPropertyColumnW...

C++ STL Set: Cannot find() last element inserted

I am in the process of writing an application in which I use the Set class in the C++ STL. I've discovered that the call to set->find() always seems to fail when I query for the last element I inserted. However, if I iterate over the set, I am able to see the element I was originally querying for. To try to get a grasp on what is going ...

How do I use TCHAR* Provided in Cmd Line Argument in Switch Statement?

Here's what I've got: switch(argv[0]) { case "-test1": AfxBeginThread(method1, 0); break; case "-test2": AfxBeginThread(method2, 0); break; case "-test3": AfxBeginThread(method3, 0); break; default: AfxBeginThread(method1, 0); break; } I'm using windows so the arguments come into the array as TCHAR*'s. What do I...

Incorrect vtable layout for class exported by DLL: request for clarification regarding headers and vtable construction.

Hello all, Although the problem at hand is solved, it has me a little confused as to what data is used to construct the vtables for a class and where the layout for the vtable is stored. If anyone can provide clarification or point me towards some information which might satiate my curiosity, I would greatly appreciate it. Background ...

Polygon in rectangle algorithm?

I have an algorithm which can find if a point is in a given polygon: int CGlEngineFunctions::PointInPoly(int npts, float *xp, float *yp, float x, float y) { int i, j, c = 0; for (i = 0, j = npts-1; i < npts; j = i++) { if ((((yp[i] <= y) && (y < yp[j])) || ((yp[j] <= y) && (y < yp[i]))) && ...

Compilation warning with Qt - Mac OS X only: <class> is already a friend of <class>

I am receiving the following warning when compiling a Qt project, but ONLY on Mac OS X with GCC. Windows with MinGW and Linux with GCC do not emit this warning. /Library/Frameworks/QtCore.framework/Versions/4/Headers/qtextcodec.h:175: warning: 'QCoreXmlStreamWriter' is already a friend of 'QTextEncoder' Why is this showing up and how c...

Design question about protocol buffer events

I am developing a system that will provide many services, say, S1, S2, S3. Each of these services have a number of executables that will communicate using events, using protobuf. My question is: Which one do you think is better design: (1) Combine all events for all the services (currently about 10-15) into one big my_events.proto defin...