c++

C++ in template initialization

Given the following piece of code: template<typename T> class MyContainer { typedef T value_type; typedef unsigned int size_type; ... }; How one should initialize variables using size_type (like loop indexes)? Should it be: for(size_type currentIndex = size_type(0);currentIndex < bound;++currentIndex) or for(size_type...

do {...} while(false)

I was looking at some code by an individual and noticed he seems to have a pattern in his functions: <return-type> function(<params>) { <initialization> do { <main code for function> } while(false); <tidy-up & return> } It's not bad, more peculiar (the actual code is fairly neat and unsurprising). It's not something I've se...

Passing data around with QMimeData in Qt drag and drop

I'm trying to understand how data gets passed around when using drag and drop in Qt. From what I understood from the examples I've been studying, you first define a widget as draggable by overriding methods inherited through QWidget. In the implementation of the overridden method, the examples I've been looking at instantiate a pointer ...

push_back to a Vector

I have a weird problem. I have a vector that I would like to push objects on to like so: vector<DEMData>* dems = new vector<DEMData>(); DEMData* demData = new DEMData(); // Build DEMDATA dems->push_back(*demData); There will be a few hundred DEMData objects in the vector. The problem is when this code is finished, all items are equ...

Get function names from call stack

I am working on an Android program which calls in to native code. That native code is segfaulting, and since getting debugging working through the android NDK is not really doable, I'm left with a callstack like the following (captured from ddms). My question is whether there is something I can manually run after the fact to translate ...

Image wont draw to screen C++

I am following a tutorial. And I am trying to draw a .bmp file to the screen. It builds with no errors but no image appears. according to the book, I should see the image pop up in random places. Below is my code. The author doesnt recommend this technique for drawing objects, he is just doing for demostration. In case your wondering. ...

Script for changing C++ class names

I have moved my classes from a global namespace into a specific namespace. I have also changed the class names. I want to convert all my source files that use these classes to the new format. I was thinking either a bash script using a sed file on Cygwin or executing a perl script. I'm having troubles with the bash script. Here's th...

Creating Steam Event using Sockets

A while back I wrote a game plugin using sockets that automatically sent invites to a steam group using a game plugin. I am attempting to do the same thing except to create events from game instead of having to login to the steam panel. Here is what I got from Wireshark when creating the event... POST: http://teamras.net/post.png GET:...

What is the best way to parse C++ class architecture in Python?

I want to parse c++ sources in Python. Namely, information about the structure of the classes. I need to construct some object in Python that should contain information about c++ class. Something like this: [namespace] function name [: parent] [constructor([parameters])] [destructor([parameters])] public methods([parameters]) private...

Invalid free while performing a std::string assign with -O2 set in g++

Before I get blasted on opening another question, this question is related to another question that I opened a few days ago: http://stackoverflow.com/questions/2303740/c-program-always-crashes-while-doing-a-stdstring-assign After investigating further based on some of the answers I came up with more questions and more information that ...

Why numeric_limits<int>::min() is differently defined?

To retrieve the smallest value i have to use numeric_limits<int>::min() I suppose the smallest int is -2147483648, and tests on my machine showed this result. But some C++ references like Open Group Base Specifications and cplusplus.com define it with the value -2147483647. I ask this question because in my implementation of the negaMa...

Remove all handlers from a boost::asio::io_service without calling them.

I want to remove all handlers from an IO_service right before I reuse it. Is this possible? I'm writing unit tests that involve an asio::io_service. In between each test case I want to clear the handlers from the global io_service. I thought that io_service::reset would to that but it doesn't. reset() only allows the io_service to b...

thread safe queue isn't thread safe if peek returns a reference even if reference is never used (with assembly!)

I have a very simple queue implementation that wraps a fixed array. It contains peek, enqueue, and dequeue. If peek returns a reference, I've found that it will return conflicting results eventually (conflicting results meaning it will return 2 different values without any intervening dequeues or enqueues). Obviously, this could happen i...

Do people still write their own data structures and algorithms?

Instead of the STL and similar libraries in other languages? As a newbie, how much should I delve into this part of software development? Breadth first or depth? Is only a conceptual understanding necessary these days? Or should I be able to implement a doubly linked list blindfolded? ...

Where would you use a friend function vs a static function?

Where would you use a friend function vs a static function? ...

What is a long pointer?

I am reading a book and it mentions certain data type as being long pointer. Just curious about what that meant. Thanks. ...

Reference initialization in C++

Hi, Can anybody explain to me why there is a difference between these two statements? class A{}; const A& a = A(); // correct A& b = A(); // wrong It says invalid initialization of non-const reference of type A& from a temporary of type A Why does const matter here? ...

3DS model loading - tree/hierarchies

I am using the 3DS loader here: http://www.flipcode.com/archives/Another_3DS_LoaderViewer_Class.shtml It does a good job of loading and rendering the model, however it lacks any sense of heirarchy. As a result, all the objects in the model render at the origin. In the code under: void Model_3DS::MainChunkProcessor(long length, long fi...

C++: Operator matches across classes

I'm trying to do the following operation: R3MeshHalfEdge *tmp_edge = half_edge; R3Vector *tmp_vector = new R3Vector(R3zero_vector); do { **tmp_vector += tmp_edge->face->plane.Normal();** tmp_edge = tmp_edge->opposite->next; }while(tmp_edge != half_edge); However, the compiler gives me the following error: R3Mesh.cp...

Passing ifstream to a function in C++

I'm trying to build 16 different suffix trees for a gene sequencing project. They're being built in main as such int main() { ifstream fp; fp.open("filepath", ifstream::in); Tree I(fp); fp.close(); I'm attempting to use them in my constructor with this code: Tree::Tree(ifstream &fp) { string current = ""; ...