c++

Corrupted singleton data using CxxTest

This is a weird problem and I'm not sure what to make of it. I have something like the following: struct Parms { const std::string value1; const std::string value2; std::string parm1; std::string parm2; Parms() : parm1(value1), parm2(value1) {} static const Parms& getDefaults() { static Parms defa...

How to use QColumnView to display multiple columns of data

I want to display data in multiple columns in a QColumnView. I am using Qt Creator and Qt 4 for development. Consider an address book application where you have multiple groups: Group 1, Group 2, etc. Your contacts can belong to any of those groups. Group 1: John Smith Pocahontas Group 2: Chief Powhatan Group 3: ... W...

How to use Boost uBLAS C++ library in an iPhone project?

I want to use Boost library in my iPhone project, specifically only boost::numeric::ublas. I managed to build static libraries for boost in order to link them in my iPhone project. However, when I look at those .a libraries I can't find one that's related to ublas (I tried ./bootstrap.sh --with-libraries=ublas in terminal but no luck). D...

How to check if you have live internet connection programmatically using C++

How can I check if I have a internet connection or live internet connection using C++? Thanks. Vibz ...

Is the Visitor Pattern the fastest way to differentiate parameter types in C++?

Is the Visitor Pattern the fastest way to accomplish method parameter type identification (effectively single dispatch on a parameter, not a member's class) in C++? I might know the exact method(s) I want to invoke on elements of not-yet-know subtype, so invariably making an additional virtual method call like V::visit(A *) in A::accept...

Cross source file template instantiation and use

I have a class with several template member functions that I would like to distribute among several source files to speed up compilation times. (The templates are implementation details and are not intended to be used outside the class, hence their definition in sources not headers.) How would I go about splitting up these templates in ...

need help converting c++ definitions to c# equivalent

Hello friends, I'm using an API (written in c++) to connect to a DVR machine, actually I only have the .dll and the .lib files, and I want to do the job in .NET (C#). So, the API doc contains definitions to all functions inside the dll, and I'm having a hard time trying to figure out how to translate those functions to equivalente C# de...

Reason reqd for the order of destructor call .?

As I have read in certain forums,when derived class object is created base class members and methods are allocated space in the memory but there is no specific base class object. Now as the derived class object goes out of scope , why derived class destructor is called first.What is the constraint of the compiler where derived class des...

Building an unordered map with tuples as keys

In a C++ program with Boost, I am trying to build an unordered map whose keys are tuples of doubles: typedef boost::tuples::tuple<double, double, double, double> Edge; typedef boost::unordered_map< Edge, int > EdgeMap; Initializing the map completes OK, however, when I try to populate it with keys and values EdgeMap map; Edge key (0...

C++ fast bit array class for streaming compression algorithms

Implementing streaming compression algorithms, one usually need a super-fast FIFO bit container class with the following functions: AddBits(UINT n, UINT nBits); // Add lower nBits bits of n GetBitCount(); // Get the number of bits currently stored GetBits(BYTE* n, UINT nBits); // Extract n Bits, and remove them The nu...

C++ anonymous class initialization

is it possible to initialize member variables in anonymous class? for example class { public: int &value; } container; ...

Type casting (from derived class)

Hello, I want to make chain-calling like jquery-way in c++. The sample: $('#obj').getParent().remove(); So, as I understand, each method of the class should return the pointer to himself (this). Everything is okay until I call base-derived methods. The code: class Base { Base *base1() { return this; } Base *base2() { return th...

visitor template for boost::variant

Hi, I would like to use a boost.variant<T0,T1,T2> as a parameter to a template 'Visitor' class which would provide visitor operators as required by the boost.variant visitor mechanism, in this case all returning void i.e., void operator()(T0 value); void operator()(T1 value); void operator()(T2 value); The template would also have fo...

selection in a lot of polylines with QGraphicsView doesn't work fine

In Qt, there is no "QGraphicsPolylineItem", so I have to implement it form QGraphicsItem. I reimplement 'paint' and 'boundingRect' functions.In 'paint()' function, I just simply draw all lines in the polyline. It's OK without any user's interaction. For selection and movable function, I reimplement the 'QPainterPath* shape()' functio...

Is 'volatile' needed in this multi-threaded C++ code?

Hello, I've written a Windows program in C++ which at times uses two threads: one background thread for performing time-consuming work; and another thread for managing the graphical interface. This way the program is still responsive to the user, which is needed to be able to abort a certain operation. The threads communicate via a shar...

Commutative property a[i] == i[a]

For a built in type integer array say int a[10]; int i = 2; a[i] = 10; alternatively i[a] = 10; because a[i] is a postfix expression that is *(a+i) or *(i+a) because commutative property of addition. I want to achieve that for a userdefined type say class Dummy { // }; Is it possible? If yes then how? If no then why? EDIT :-...

Need help with WM_KEYDOWN

I need help with WM_KEYDOWN, I want to remove the "pause" between the first keypress and the repeating keypresses. If you continually hold down a button, I want the program to realize it directly. Im trying to make a game with directx. Please tell me if I should use something else than WM_KEYDOWN. ...

Android and C++: Necessary?

Just checking out Android development very superficially, and it seems that most everyone is working in Java. Yet Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework. does this mean that, in Andro...

extern problems with array of structures c++

I have the main .cpp file with this: #include "stdafx.h" #include "Form1.h" #include <iostream> ... #include <stdio.h> const int MAX_LEN = 1000; struct DataLine { char StartCode; int ByteCount; int Address; int RecType; int DBytes[16]; int Checksum; }; DataLine AllData[MAX_LEN]; Then I have a form.h with ...

STL: set_union, includes, mismatch, find_if but is there no includes_any?

From the title you'd almost assuredly think use set_union to create a list and then check if it's empty. However, the objects I'm comparing are "expensive" to copy. I've looked at includes but that only works if all the items of one list are found in another. I've also looked at mismatch but rejected it for obvious reasons. I can and...