c++

C++: A variation of priority queue

I need some kind of priority queue to store pairs <key, value>. Values are unique, but keys aren't. I will be performing the following operations (most common first): random insertion; retrieving (and removing) all elements with the least key. random removal (by value); I can't use std::priority_queue because it only supports removin...

Difference between boost::ref and regular references

What is the difference between boost::ref(i) and & i ? What are the situations where we cannot use regular references and have to go for boost::ref instead? Please include examples if possible. ...

C++ MFC server app with sockets crashes and I cannot find the fault, help!

My program has one dialog and two sockets. Both sockets are derived from CAsyncSocket, one is for listening, other is for receiving data from client. My program crashes when client tries to connect to server application and server needs to initialize receiving socket. This is my MFC dialog class. class CFileTransferServerDlg : public C...

shared memory STL maps

Hello, I am writing an Apache module in C++. I need to store the common data that all childs need to read as a portion of shared memory. Structure is kind of map of vectors, so I want to use STL map and vectors for it. I have written a shared allocator and a shared manager for the purpose, they work fine for vectors but not for maps, bel...

DB2 Transaction Logs

How to read Transaction Logs of DB2 in iSeries / AS/400. Is there any C or C++ or Java API Any help is appreciated? ...

Illegal token on right side of ::

I have the following template declaration: template <typename T> void IterTable(int& rIdx, std::vector<double>& rVarVector, const std::vector<T>& aTable, const T aValue, T aLowerBound = -(std::numer...

Is there any cross-platform threading library in C or C++?

Hello, I'm looking for some easy to use cross-platform threading library written in C or C++. What's your opinion on boost::thread or Pthreads? Does Pthreads run only on POSIX compliant systems? What about the threading support in the Qt library? Thanks for any hints. ...

GDI polyline partial output when printing

I'm seeing a strange problem when calling Win32 GDI Polyline() when printing out. On screen it all looks ok, however if printing it will stop the polyline when it encounters a large value. I think this discrepency is due to the scaling for printing yielding larger POINT values. It appears as if the polyline stops drawing if it hits ...

How to get MAC address of bluetooth HID device?

Hello, how can I get the MAC address of a bluetooth device which connected as HID device? I have handle to the device Handle = CreateFile(didetail->DevicePath, 0, FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, NULL); but I can't find how to get the MAC address. C++; Windows ...

NULL pointer comparison fails

Hello, I'm initializing in a class a pointer to be NULL. Afterwards I check if it is NULL in the same class. But it's not always 0x0. Sometimes it's 0x8 or 0xfeffffff or 0x3f800000 or 0x80 or other strange stuff. In most case the pointer is 0x0 but sometimes it gets altered somehow. I'm sure that I'm not changing it anywhere in my code...

Converting C++ string/wchar_t* to C# string ?

Question: I need to call a C# dll from a C++ executable. I use COM, and it works fine for int, long and bool. But I can't get a string along... The IDL file says it's a BSTR, but I can't pass it correctly, and neither retrieve one. I tried using wchar_t* and using sysalloc as I did with VB6, but that doesn't seem to work. Anybody knows...

C++: need indexed set

I need an indexed associative container that operates as follows: initially empty, size=0. when I add a new element to it, it places it at index [size], very similar to a vector's push_back. It increments the size and returns the index of the newly added element. if the element already exists, it returns the index where it occurs. S...

Why is only the second array dimension important?

Why when working with two dimensional arrays only second dimension is important for a compiler? Just can't get my head around that. Thanks ...

Storing a type in C++

Is it possible to store a type name as a C++ variable? For example, like this: type my_type = int; // or string, or Foo, or any other type void* data = ...; my_type* a = (my_type*) data; I know that 99.9% of the time there's a better way to do what you want without resorting to casting void pointers, but I'm curious if C++ allows this...

Specializing a template on a lambda in C++0x

I've written a traits class that lets me extract information about the arguments and type of a function or function object in C++0x (tested with gcc 4.5.0). The general case handles function objects: template <typename F> struct function_traits { template <typename R, typename... A> struct _internal { }; template <typename ...

Is it good to have a member template function inside a non-template class in c++?

I wonder if it is a good practice to have a member template function inside a non-template class in c++? Why? I'm trying to do something like this in classA.h: classA { public: member_func1(); member_func2(); }; in classA.cpp: template <class T> share_func(); classA::member_func1() { call share_func(); } classA::mem...

How to have struct members accessible in different ways

I want to have a structure token that has start/end pairs for position, sentence, and paragraph information. I also want the members to be accessible in two different ways: as a start/end pair and individually. Given: struct token { struct start_end { int start; int end; }; start_end pos; start_end sent; start_end p...

Pointers in For loops

Quick question: I am a C# guy debugging a C++ app so I am not used to memory management. In the following code: for(int i = 0; i < TlmMsgDB.CMTGetTelemMsgDBCount(); i++) { CMTTelemetryMsgCls* telm = TlmMsgDB.CMTGetTelemetryMsg(i); CMT_SINT32_Tdef id = telm->CMTGetPackingMapID(); ManualScheduleTables.SetManualMsg(i,id); ...

I keep Getting Control reaches end of non-void function. What am I doing wrong?

location pick(void){ // generates a random location location get; get.x = rand() % FIELD_SIZE + 1; int forY = rand() % FIELD_SIZE +1; switch(forY){ case 1: get.y = 'a'; break; case 2: get.y = 'b'; break; case 3: get.y = 'c'; break; case 4: ...

Ways std::stringstream can set fail/bad bit?

A common piece of code I use for simple string splitting looks like this: inline std::vector<std::string> split(const std::string &s, char delim) { std::vector<std::string> elems; std::stringstream ss(s); std::string item; while(std::getline(ss, item, delim)) { elems.push_back(item); } return elems; } S...