c++

struct with list<..> in 2 dim. dynamic array segfaults on delete

Hey there, for a little project i wanted to use a struct with an stl container in it. This thingy is then packet into a dynamic 2 dim. array, but when i try to delete it, it segfaults. Here is the code: struct cell{ list<pair<double, double> > alist; }; int main() { struct cell ** myAr = new cell*[5]; for(int i = 0; i < 5; ...

What kind of projects should I do to teach myself C#/C/C++?

I am right now pretty experienced with scripting languages, especially Ruby, JavaScript and PHP. Now I want to learn some more powerful languages and I think C# is the best choice for me. After that I'd like to learn C, because most of the people say it's a “must-have” and that it gives you a better understanding of programming. Maybe I ...

Templated map / multimap function in C++

Assume I have: std::map<K, V1> m1; std::multimap<K, V2> m2; I would like to template by container type and by key/value type. The following isn't working however :/ template <typename T> void do_something(T var) { // do something } template <typename TContainer, typename TKey, typename TVal> void func(const TContainer<TKey, TVal>&...

Element and Event inspection in QML (QT Declarative)

Hi everyone, I am doing some tests in Qt Quick (Qt Declarative and QML), and i would like to inspect the elements composing the declarative interface. For example, if i have a declarative GUI composed of a rectangle and two images, i would like to have a list with three (or more) elements with these widgets (or items in Qt Declarative)...

Uninitialized Automatic variable forcing value to random value

Hi All, This may look like a trivial problem. Sorry in that case, I am not able to find the actual way. I understand that automatic variable are un-initilaized. So a code snippet provided below is likely to dump in block-2 char *p; if(NULL == p) { //do something block-1 statement } else { //do something else block-...

C++ / openGL: Rotating a QUAD toward a point using quaternions (updated)

When I have a QUAD at a certain position, how can I rotate it in such a way that its normal points toward a given point? Imagine the colored blocks are just rectangular quads, then this image shows a bit what I mean. The quads are all oriented in such a way they point toward the center of the sphere. Maybe this second image shows a bi...

How do I make my BigInt and BigFraction classes interact with fundamental data types in C++

I created my own big integer class, and big fraction class (which stores the numerator and denominator as 2 BigInt member variables). I overloaded the +,-,*,/ operators and the classes work fine. Now I want to extend them so that for example a BigInt can be added to an int painlessly, see below: int i; BigInt I1, I2; BigFrac F1, F2...

Debug heap memory leak detection - strange results?

I think my C++ application is tight and doesn't leak any memory. Long running stress tests and static code analyzers seem to indicate as much. However, when exercising a very complex usage szenario the Visual Studio 2008 built in debug heap will show a couple of warnings like the following on exit: Detected memory leaks! Dumping objects...

Medians of upper and lower halves of a vector

I am trying to compile an Octave .oct function to calculate the medians of the upper and lower "halves" of a sorted vector which will vary in length e.g. for an odd length vector such as [5,8,4,6,7] I want the "lower" median value of 4,5 and 6 and the "upper" median value of 6,7 and 8 (6 is part of both calculations), and for an even len...

C/C++: which school of reporting function failures is better.

Very often you have a function, which for given arguments can't generate valid result or it can't perform some tasks. Apart from exceptions, which are not so commonly used in C/C++ world, there are basically two schools of reporting invalid results. First approach mixes valid returns with a value which does not belong to codomain of a f...

Why the var and * to var gives diff values in this example of const_cast

Check this example for const_cast of int. I am using VC++ 2008 to compile this. #include <iostream> using namespace std; void main() { const int x=0; int y=90; int *p = const_cast<int *> (&x); *p=y; cout<<" value of x: "<<x<<" addr of x "<<&x<<endl <<" and *p : "<<*p<<" and addr p "<<p<<endl; } ================ The output is ...

Qt Slot won't connect to DBus signal

Here is my problem: I send this message on my DBus session bus : signal sender=:1.3 -> dest=(null destination) path=/; interface=a.a.a; member=a here is my code : dbus_interface.h : #ifndef DBUS_INTERFACE_H #define DBUS_INTERFACE_H #include <QtCore/QObject> #include <QtCore/QString> #include <QtDBus/QtDBus> class dbus_interface :...

What's the best way to sum the result of a member function for all elements in a container?

Let's say I have the following object: struct Foo { int size() { return 2; } }; What's the best way (most maintainable, readable, etc.) to get the total size of all objects in a vector<Foo>? I'll post my solution but I'm interested in better ideas. Update: So far we have: std::accumulate and a functor std::accumulate and a la...

How do I build all configurations of a Visual Studio 2008 C++ project on the command line?

I'd like to build all the configurations of a VS 2008 C++ project on the command line. Something like: devenv TheProject.vcproj /build /nologo But this doesn't work because the /build command insists on having a configuration following it like this: devenv TheProject.vcproj /build "Release|Win32" /nologo Is there a way to get...

C++ code/XML generation tools

I'm not sure what exactly the right term is, kind of like ORM using XML as the data store. Are there any decent tools which will autogenerate C++ classes (including data and serialization/deserialization) based on an XML schema? Or will create XML-sync code and schema based on a C++ class definition? TinyXML is great but it's so old-sch...

logic behind the code

could any one explain me logic behind this code?? pt1.x = cvRound(x0 + 1000*(-b)); pt1.y = cvRound(y0 + 1000*(a)); pt2.x = cvRound(x0 - 1000*(-b)); pt2.y = cvRound(y0 - 1000*(a)); ...

Remove environmental variable programmatically

I need to write a unit test for some C++ code that checks for the presence of an environmental variable. I'm using MSVS 2008 and gtest as my framework. I add the environmental variable using putenv, I check the environmental variable using getevn, but I can't figure out how to remove it so that no other test will see it. I realize this i...

C++ basic constructor question

Hello! How should I handle the following situation : I am writing my own 2D vector class and have the following code: class Vector2 : public (...) public: Vector2(float x, float y) { local_vector_storage_[0] = x; local_vector_storage_[1] = y; } template <typename Iterator> Vector2(Iterator begin, Iterator end) ...

Listing certificates from a CAC without pin

I'm developing a CAC authentication app. I'm running RHEL 5.5 and have a card reader attached to my machine. When I insert a smart card/CAC, there is a popup notification that comes on the upper right hand side on the window where the clock is and the "Smart Card Manager" GUI is accessible clicking on the icon (card with lock on it) tha...

register for WindowServer CGScreenRefreshCallback CGScreenUpdateMoveCallback in C++

Hi everybody, I'm trying to register for CGScreenRefreshCallback and CGScreenUpdateMoveCallback ( here's what apple's saying about http://developer.apple.com/mac/library/documentation/GraphicsImaging/Reference/Quartz_Services_Ref/Reference/reference.html#//apple_ref/doc/uid/TP30001070-CH1g-F16970 ) using C++ only. I wrote this simple te...