c++

Portable way to "fork()" in QT application?

Say, i need to run a bunch of code that is prone to crash so i need to run it on a different process. Typically i'd do it something like this: pid = fork(); if (pid == -1) { std::cout << "Cant Spawn New Thread"; exit(0); } else if (pid == 0) { std::cout << "Im a child that will crash\n"; char *foo = (char *) 0xffff...

testing ipv6 applications

Hi All, I have a network application that I need to convert so that it works for ipv6 network. Could you please let me know what I need to do (replace socket APIs)? One more thing, how can I test my application? Thanks. ...

Adding and removing items without invalidating iterators

I have an object that has a list of 'observers'. These observers get notified of things, and they might respond to this change by adding or removing themselves or other observers from the object. I want a robust, and not unnecessarily slow, way to support this. class Thing { public: class Observer { public: virtual void o...

Really strange problem with just in time debugging and filestreams

Hello all, I developed a small program which was working fine until I made a really minor change in some unrelated part of the code. From that point onwards the program throws an unhandled win32 exception and Microsoft Visual Studio Just in time debugger kicks in. I am using codeblocks and my compiler is the gcc compiler. What is frust...

Why can't I access a protected member from an instance of a derived class?

I haven't done C++ in a while and can't figure out why following doesn't work: class A { protected: int num; }; class B : public A { }; main () { B * bclass = new B (); bclass->num = 1; } Compiling this produces: error C2248: 'A::num' : cannot access protected member declared in class 'A' Shouldn't protected members be ...

How to implement independent rendering layers in Direct3D9?

I'm working on a windowed Direct3D data plotting application that needs to display multiple overlays on top of the data (similar to HUDs in games). Since there could be a large amount of data that needs plotting, and not all overlays will be changed every time, I figured it wouldn't be a good idea to replot verticies when only one overl...

Search for multiple occurrences of a value in a character array and then listing # of occurrences. VC++

I'm trying to write a small program that will generate a parity bit for Hex and Binary values pulled from an ASCII character array. I have a total of 3 character arrays. For example: const char *caASCII[] = {"A", "B", "C", ...}; const char *caASCIIBinary[] = {"01000001", "01000010", "01000011", ...}; const char *caASCIIHex[] = {"41", ...

methods vs. functions

I keep on getting confused about this design decision a lot of the time when I'm writing programs, but I'm not 100% sure when I should make a function to be a member function of a class, when to leave it as a normal function in which other source files can call the function when the function declaration is exposed in a header file. Does ...

binary tree numNodes

int numNodes() const { int size = 1; if (left != NULL) size += left->numNodes(); if (right != NULL) size += right->numNodes(); return size; } the code above is the code to find number of nodes inside a tree, as it is using recursive call, I don't really understand what it does. could anyone please explain how recursive ca...

Make thumbnails point to real image

I have a QHBox with a custom widget that inherits QLabel which iterates through all image files in a dir and generates a thumbnail. This part is working fine, however I need to implement the functionality to display the original image from which the thumbnail was generated in a central QLabel widget for diplaying pictures. What would b...

Creating program libraries in Windows and LINUX [C++]

I am planning to use libraries in my C++ program. Development is happening on LINUX but application is designed to compile on both LINUX and Windows. I understand direct equivalent for shared libraries(.so) in windows is DLL, right? In LINUX using g++, I can create shared library using -fPIC and -shared flags. AFAIK, there is no other ...

Access violation after catching dll exception

I have to load modules as dlls dynamically at runtime as they are not known ahead of time, just that they conform to a class interface. What I noticed is that after I catch an exception thrown by the dll (in the main program in the main thread), the right destructors are called and the modules destroyed and dll's unloaded, but then as t...

determine size of array if passed to function

Is it possible to determine the size of an array if it was passed to another function (size isn't passed)? The array is initialized like int array[] = { XXX } .. I understand that it's not possible to do sizeof since it will return the size of the pointer .. Reason I ask is because I need to run a for loop inside the other function wher...

Sending string data between threads (Win32)

Hi all, This is a fairly straightforward question, I'm basically looking for a 'best practice' approach to what I'm trying to do. I have a Win32 GUI application which starts up a worker thread to do a bunch of blocking calls. I want this thread to send string messages back to the GUI so they can be displayed to the user. Currently I'm...

How to run regasm.exe from a C++ program?

Hi I want to write a program which runs regasm.exe to create a tlb file programatically. How can I do this?? Ur help is greatly appreciated... Thanks in advance. ...

What could cause a deterministic process to generate floating point errors

Having already read this question I'm reasonably certain that a given process using floating point arithmatic with the same input (on the same hardware, compiled with the same compiler) should be deterministic. I'm looking at a case where this isn't true and trying to determine what could have caused this. I've compiled an executable an...

GetPrivateProfileSectionNames always returns 0

GetPrivateProfileSectionNames always returns 0, even when the file is a valid ini file. What can be the reason? Thanks in advance! ...

Virtual Calls using address of pure virtual member. Is it legal?

Hello Group, I read sometime back (probably on c.l.c++.moderated) that virtual function calls can be templatized. I tried something on the following lines. #include <iostream> template<class T, class FUN> void callVirtual(T& t, FUN f){ (*t.*f)(); } struct Base{ virtual ~Base(){} virtual void sayHi()=0; }; struct D...

Error C2678 after migrating C++ code from VC6 to VS2008 - no operator found which takes a left-hand operand of type 'type'

This piece of code compiles file in VC6 but in VS 2008 it gives an error. Can anyone tell me why? I guess it is because you can no longer compare a pointer to NULL (which is a typedef for 0). If that is the case, how do I do this comparison in VC9? for ( std::vector<aCattrBase*>::iterator iT = attrLst.begin(); iT < attrLst.end(); iT++) ...

Dynamic SQL vs Static SQL

Hi All, In our current codebase we are using MFC db classes to connect to DB2. This is all old code that has been passed onto us by another development team, so we know some of the history but not all. Most of the Code abstracts away the creation of SQL queries through functions such as Update() and Insert() that prepend something like...