c++

Use C function in C++ program; "multiply-defined" error

I am trying to use this code for the Porter stemming algorithm in a C++ program I've already written. I followed the instructions near the end of the file for using the code as a separate module. I created a file, stem.c, that ends after the definition and has extern int stem(char * p, int i, int j) ... It worked fine in Xcode but it ...

Getting value of std::list<>::iterator to pointer?

How can i loop thru a stl::List and store the value of one of the objects for use later in the function? Particle *closestParticle; for(list<Particle>::iterator p1 = mParticles.begin(); p1 != mParticles.end(); ++p1 ) { // Extra stuff removed closestParticle = p1; // fails to compile (edit from comments) } ...

Drawing connected lines with OpenGL

I'm drawing convex polygons with OpenGL. I then do the same thing but use GL_LINE_LOOP. The problem I have is the lines are not always connected. How could I ensure that the lines are always connected? In the photo below, Iv highlighted in green, the corners that are connected and in red, those that are not. I would like for them to be ...

Moving from Windows to Ubuntu.

Hello there, I used to program in Windows with Microsoft Visual C++ and I need to make some of my portable programs (written in portable C++) to be cross-platform, or at least I can release a working version of my program for both Linux and Windows. I am total newcomer in Linux application development (and rarely use the OS itself). S...

C++ Conceptual problem with (Pointer) Pointers

I have a structure usually containing a pointer to an int. However, in some special cases, it is necessary that this int pointer points to another pointer which then points to an int. Wow: I mentioned the word pointer 5 times so far! Is this even possible? I thought about it that way: Instead of using a second int pointer, which is m...

Modelling boost::Lockable with semaphore rather than mutex (previously titled: Unlocking a mutex from a different thread)

I'm using the C++ boost::thread library, which in my case means I'm using pthreads. Officially, a mutex must be unlocked from the same thread which locks it, and I want the effect of being able to lock in one thread and then unlock in another. There are many ways to accomplish this. One possibility would be to write a new mutex class ...

C++ User-Defined Vector

How do you declare a vector in c++ while allowing user input to define the vector's name? Okay, after reviewing your responses, here is more detail; Here is the error message from VS08 C++ console application - Error 2 error C2664: 'std::basic_istream<_Elem,_Traits> &std::basic_istream<_Elem,_Traits>::get(_Elem *,std::streamsize)' : c...

Which is G++ 4.4.1 default allocator?

I was wondering which is the default memory allocator in G++ 4.4.1, on Ubuntu 9.1. I am interested in comparing different C++ allocators in a multithreaded environment. And where can I get more information about the default memory allocator? EDIT: I refer to new and delete operators. The only linking is to rt and pthread Regards ...

Windows Programming: ID2D1Bitmap Interface - Getting the Bitmap Data

I've been writing my own library of functions to access some of the new Direct2D Windows libraries. In particular, I've been working on the ID2D1Bitmap interface. I wanted to write a function to return a pointer to the start of the bitmap data (for the editing of particular pixels, or custom encoding or whatever else I might wish for in ...

Access violation writing location, in my loop

The exact error I am getting is First-chance exception at 0x0096234a in chp2.exe: 0xC0000005: Access violation writing location 0x002b0000. Windows has triggered a breakpoint in chp2.exe. And the breakpoint stops here for(DWORD i = 0; i < m; ++i) { //we are start at the top of z float z = halfDepth - i*dx; for(DWORD j = ...

Passing around objects to network packet handlers ?

Hey, I've been writing a networking server for a while now in C++ and have come to the stage to start looking for a way to properly and easily handle all packets. I am so far that I can figure out what kind of packet it is, but now I need to figure out how to get the needed data to the handler functions. I had the following in mind: ...

How to use folders in VC10

When making a .NET project, then you can create folders in your solution explorer and these are real folders on the hard drive. When using C++ however they are only filters. Is there a way to set filters to be actually folders? ...

what "Debug Assertion Failed" mean and how to fix it, c++?

hi, why this program gives me a "Debug Assertion Failed" Error Message while running #include "stdafx.h" #include "iostream" #include "fstream" #include "string" using namespace std; int conv_ch(char b) { int f; f=b; b=b+0; switch(b) { case 48: f=0; break; case 49: f=1; break;...

Good style for handling constructor failure of critical object

I'm trying to decide between two ways of instantiating an object & handling any constructor exceptions for an object that is critical to my program, i.e. if construction fails the program can't continue. I have a class SimpleMIDIOut that wraps basic Win32 MIDI functions. It will open a MIDI device in the constructor and close it in the...

BST Level Traversal

Ok, so I'm trying to do a level order traversal of a binary search tree and its not working. The code below makes sense to me, but that is probably because I've been looking at it forever and I've convinced myself that it should work. void BST<T>::levelByLevel(ostream &out) { Queue<BinNodePointer> q; BinNodePointer subtreeRoot; i...

How to list all installed ActiveX controls?

I need to display a list of ActiveX controls for the user to choose. It needs to show the control name and description. How do I query Windows on the installed controls? Is there a way to differentiate controls from COM automation servers? ...

wrapping boost::ublas with swig

I am trying to pass data around the numpy and boost::ublas layers. I have written an ultra thin wrapper because swig cannot parse ublas' header correctly. The code is shown below #include <boost/numeric/ublas/vector.hpp> #include <boost/numeric/ublas/matrix.hpp> #include <boost/lexical_cast.hpp> #include <algorithm> #include <sstream> #...

How to return the handle of a window when we click on it, without any DLL injection?

Hello! For one of my projects, I need to create a function that will return a handle to a window when the user click on it (any window displayed on screen, and anywhere inside that window). I know it is possible to use a global hook, but I think there must be a more simple way of doing that, without using any DLL injection. In fact, I ...

Importing a C DLL's functions into a C++ program

I have a 3rd party library that's written in C. It exports all of its functions to a DLL. I have the .h file, and I'm trying to load the DLL from my C++ program. The first thing I tried was surrounding the parts where I #include the 3rd party lib in #ifdef __cplusplus extern "C" { #endif and, at the end #ifdef __cplusplus } // ext...

Can't Include winhttp.h (with code::blocks/mingw) c++

I've been trying to include winhttp.h and I get this error: Winhttp.h: No such file or directory Mingw doesn't have it, how would I add it? ...