c++

OOPs paradigm in Python

Here is something I've been having a doubt about. Consider the following snippet. class A(object): def check(self): super(A, self).check() print "inside a" class B(object): def check(self): print "inside b" class C(A, B): pass c = C() c.setup() Now this gives the output, inside b inside a Pass...

Which of these is better practice?

Let's say I have a class FOO. I want to have a std::vector of FOO. Is it better if I do something like this: FOO foo; foo.init(); foo.prop = 1; std::vector<FOO> myvec; myvec.push_back(foo); foo.prop = 2; myvect.push_back(foo); or is it better practice to do: std::vector<FOO> myvec; FOO foo; myvec.push_back(foo); myvec.back().init(...

Simple-iphone-image-processing source code question, what does this do

Hi, I am going through the source code for the above project and I don't understand the following lines of code can anyone help explain it to me please? I am trying to get the code to work with color images as it currently only works with greyscale images. I have the main methods working however the filters only get applied to the top qu...

STL container function return values

When looking over the member functions of the STL containers, an odd thought occurred to me. Why don't functions like std::vector<T>::push_back(T) not have an (optional) return value (iterator or even a reference to the appended object)? I know std::string functions like insert and erase return iterators, but that's for obvious reasons. ...

Object Oriented Design Problem, Liskov Substitution Principle

Hi everybody, I'm making the design of a OO framework and I'm facing the following problem. Let's say that in the framework I have a Shape interface and the users are free to implement and extends (adding new functions) the Shape interface to create their own figures, e.g. Square and Circle. To make these new objects available the user...

Is quick sort followed by binary search faster than linear search?

Is it better to sort then binary search or simply linear search? Thanks ...

Link the static versions of the Boost libraries using CMake

I've got both the static and the dynamic versions of the boost libraries in /usr/lib. Now I'd like CMake to prefer the static versions during the linkage of my executable. What can I do? Thank you ...

Need advice in converting in one of the legacy C++ component into C#

Currently, we are working on a C++ legacy code base, which consists of several software components. One of the components, are written in a way that is extremely difficult to maintain. (For example, memory allocation is done in X place, but memory de-allocation is done in Y place. This make memory management a painful job). Till now, we...

C++ FSM design and ownership

Hi, I would like to implement a FSM/"pushdown automaton" parser for this syntax: http://stackoverflow.com/questions/3025293/c-general-parser-with-scopes-and-conditionals which has already been "lexed" into http://stackoverflow.com/questions/3085070/finite-state-machine-parser I have the following: class State { public: virtual Sta...

Under what circumstances will C++ fail to call an inherited class's constructor?

EDIT following resolution, this has been substantially edited to dump irrelevant detail and explain the real issue. I found a problem recently in some old code. The particular code was only rarely used and had insufficient unit tests (I was adding some more when I spotted the problem). I only relatively recently stopped using Visual C++...

[Qt/C++] Need some updated examples on how to use QListView ...

Hi all ... Does anyone have any links to tutorials showing how to use QListView and how to populate it with items .. ? If I search google I can only find outdated tutorials which use classes which have been deprecated .. ...

How to use c++ std complex numbers in QtScript

Hello everyone, I try to find out how to use complex numbers in QtScripts such that slots defined with complex arguments can be called from a QtScript. Also basic algebra (+,-,exp, ... ) of complex-numbers should be accessible to the user from the script. Just for illustration want I want to call is: #include<complex> typedef complex<...

To code background process in Ruby or C++ for rails app?

I've been working on a rails app for a couple of days now that I need an underlying "middle layer" for that connects my rails application to the various services that make up the data. The basic setup looks like this: Frontend ("Rails app") -> user requests data to be aggregated -> info goes in database and a JSON request is sent to "...

Files in directory in C++

How to get all files in a given directory using C++ on windows? Note: I found methods that use dirent.h but I need a more standard way... Thanks ...

C/C++: Pointers within Const Struct

How do I force const-ness of the memory pointed to by obj->val1 in the function fn? #include <iostream> struct foo { int* val1; int* val2; int* val3; }; void fn( const foo* obj ) { // I don't want to be able to change the integer that val1 points to //obj->val1 = new int[20]; // I can't change the pointer, *...

[Qt] Need help in transferring a file using Email/Bluetooth/Social Network ...

Hey guys, I need some general information on how can I use Qt to send a file using email or bluetooth or a social network already defined in the N900 (e.g. facebook) .. Regarding bluetooth, I read that Qt doesn't provide any libraries, and you would have to use Qt Extended, or use the default Maemo libraries ... I also know that for ge...

GlBufferDataARB is giving me memory issues

Basically I do something like this: GenerateLinePoly(Contour[i].DrawingPoints, Contour[i].Outline.OutlineWidth); Contour[i].Outline.OutlineSize = OutlineVec.size() / 2; glBindBufferARB(GL_ARRAY_BUFFER_ARB,Contour[i].Outline.OutlineVBO); glBufferDataARB(GL_ARRAY_BUFFER_ARB,sizeof(GLfloat) * OutlineVec.size(), &Outlin...

C++: is the unordered_map really unordered?

I am very confused by the name 'unordered_map'. The name suggests that the keys are not ordered at all. But I always thought they are ordered by their hash value. Or is that wrong (because the name implies that they are not ordered)? Or to put it different: Is this typedef map<K, V, HashComp<K> > HashMap; with template<typename T> s...

RTTI for distributed system?

Can one use RTTI for distributed systems? If so, what are the disadvantages? too slow, too much memory or performance unpredictable? Thanks ...

usual hashtable implementation compared to tree

Usually (as in C++), the hash function returns any size_t value -- thus many different hash values are possible (2^32). That is why I always thought that when people talked about them being implemented as tables, that is not really true in practice because the table would be much too big (2^32 entries). Of course my assumption was wrong...