c++

Concat Macro argument with namespace

I have a macro, where one of the arguments is an enum value, which is given without specifying the namespace scope. However somewhere inside the macro I need to access it (obviously I must define the namespace there), but I can't seem to concat the namespace name with the template parameter. Given the following samplecode the compiler co...

Why is my recursiveMinimum function not working?

#include <iostream> using namespace std; int recursiveMinimum(int [], int n); int main () { int theArray[3] = {1,2,3}; cout << recursiveMinimum(theArray, 0); cout << endl; return 0; } // pass in array and 0 to indicate first element // returns smallest number in an array int recursiveMinimum (int anArray[], int n) /...

How to serialize shared/weak pointers?

I have a complex network of objects connected with QSharedPointers and QWeakPointers. Is there a simple way to save/load them with Boost.Serialization? So far I have this: namespace boost { namespace serialization { template<class Archive, class T> void save(Archive& ar, QSharedPointer<T> const& ptr, unsigned version...

Any good C or C++ libraries out there for dealing with large point clouds?

Basically, I'm looking for a library or SDK for handling large point clouds coming from LIDAR or scanners, typically running into many millions of points of X,Y,Z,Colour. What I'm after are as follows; Fast display, zooming, panning Point cloud registration Fast low level access to the data Regression of surfaces and solids (not as imp...

Custom UIs in C++ with Qt?

Coming from C#, I've decided to learn C++ with the Qt framework. I have one question though, what is the "correct" way to accomplish an UI like this one? This may be kind of subjective, but I'm sure that stacking image labels on top of each other isn't the right way. ...

C++, is linking order standardized?

On my linux box, I have 2 libraries: libfoo1.a and libfoo2.a and they both contain an implementation of void foo(int) and my main program calls foo: int main() { foo(1); return 0; } I compiled the program two ways using g++ g++ main.cpp libfoo1.a libfoo2.a -o a1.out g++ main.cpp libfoo2.a libfoo1.a -o a2.out When I run the ...

For real-time application, which is better C or C++?

I’m electronic engineer with experience with both language C and C++ (I wrote with C for micro-controller and with C++ I wrote for Windows with Borland C++ Builder) My company develops motor control products, and we are working with STM32 and IAR compiler. I recognize the technical differences between the languages, I interest in the d...

How to construct a container of MyClass, where MyClass constructor can throw?

I have something like: #include "MyImage.hpp" // MyImage wraps the Qt library image class namespace fs = boost::filesystem; class ImageCollection { public: ImageCollection(const char* path); private: const fs::path path_; deque<MyImage> instanceDeque_; } ImageCollection(const char* path) : path_(fs::is_directory(path) ? ...

using a class member to initialize a parent class

I have a basic_iostream derived class like this: class MyStream : public std::basic_iostream< char >, private boost::noncopyable { public: explicit MyStream( SomeUsefulData& data ) : buffer_( data ), std::basic_iostream< char >( &buffer_ ) { }; ~MyStream() { }; private: //...

reading from file certain lines at a time in c/c++

Hello, So i have a gui, designed using QT, c++. I have large amount of data in a text file that I would like to read in this fashion: load first 50 lines, when the user scrolls down load next 50 lines and so one. When the user scrolls up load previous 50 lines. Thank you. ...

design exercise preferably using mfc

i was told to design a paintbrush program in 2 variation , one that uses lots of space and little cpu and the other vice versa. the idea (as i was told- so not sure) is somehow to save the screen snapshots versus saving XOR maps (which i have no idea what it means) who represent the delta between the painting. can someone suggest a wa...

Destructor order

I have a C++ class hierarchy that looks something like this: class A; class B { public: B( A& a ) : a_( a ) { }; private: A& a_; }; class MyObject { public: MyObject() : b_( a_ ) { }; private: A a_; B b_; }; Occasionally, it will happen that in B's destructor I will get invalid access exceptions...

When overriding a virtual member function, why does the overriding function always become virtual?

Hi! When I write like this: class A { public: virtual void foo() = 0; } class B { public: void foo() {} } ...B::foo() becomes virtual as well. What is the rationale behind this? I would expect it to behave like the final keyword in Java. Add: I know that works like this and how a vtable works :) The question is, why C++ st...

declaring the unix flavour in C/C++

how do i declare in C/C++ that the code that is written is to be built in either HP-UX or solaris or AIX? ...

x86: howto catch data-alignment faults (aka SIGBUS on sparc)

Is it somehow possible to catch data-alignment faults even on i386? Maybe by setting a i386 specific machine register or something like that. On Solaris-Sparc I am receiving a SIGBUS in this case, but on i386 everything is fine. Environment: 32-bit application Ubuntu Karmic gcc/g++ v4.4.1 EDIT: Here is why I am asking this: our ...

Is Pointer-to- " inner struct" member forbidden ?

Hi! i have a nested struct and i'd like to have a pointer-to-member to one of the nested member: is it legal? struct InnerStruct { bool c; }; struct MyStruct { bool t; bool b; InnerStruct inner; }; this: MyStruct mystruct; //... bool MyStruct::* toto = &MyStruct::b; is ok but: bool MyStruct::* toto = &MyStruct::in...

Changable return data type in C++

I'm writing a matrix class, and I want it to be able to store any different (numerical) data type - from boolean to long. In order to access the data I'm using the brackets operator. Is it possible to make that function return different data types depending on which data type is stored within the class. What's MORE is that I'm not entir...

C vs C++ code optimization for simple array creation and i/o

I've been trying to convince a friend of mine to avoid using dynamically allocated arrays and start moving over to the STL vectors. I sent him some sample code to show a couple things that could be done with STL and functors/generators: #include <iostream> #include <vector> #include <algorithm> #include <iterator> #define EVENTS 100000...

Struct instantiation from void pointer buffer

Here's some C++ code that just looks funny to me, but I know it works. There is a struct defined, and in the program we allocate memory using a void pointer. Then the struct is created using the allocated buffer. Here's some code typedef struct{ char buffer[1024]; } MyStruct int main() { MyStruct* mystruct_ptr = 0; void* ...

How to know if the windowstation attached is interactive?

I am writing a program that can be loaded by another service (under our control), or by the logged-on user. The program needs to know if the window station is interactive in order to display dialogs. I know GetProcessWindowStation function, but this one returns a handle. Is there a way to find out? ...