c++

example how to do multiple inherit ?

Can somebody give me a example: How do i multiple inherit int, float from first class and char, string from second class into the third class ? ...

How to do a double-chunk add with no undefined behaviour?

EDIT Public health warning - this question includes a false assumption about undefined behaviour. See accepted answer. After a reading recent blog post, I've been thinking a lot about the practicality of avoiding all standards-undefined assumptions in C and C++ code. Here is a snippet cut out of C++, to do an unsigned 128-bit addition.....

find four elements in array whose sum equal to a given number X

hello, I need help to find an algorithm that finds: four elements in array whose sum equal to a given number X in O(n^2*log(n)) prefer in pseudo-code or c,c++ thanks moti ...

abort() is not __declspec(noreturn) in VS2010

In my copy of VS2010, stdlib.h contains (lines 353-355) _CRTIMP __declspec(noreturn) void __cdecl exit(_In_ int _Code); _CRTIMP __declspec(noreturn) void __cdecl _exit(_In_ int _Code); _CRTIMP void __cdecl abort(void); I find it strange that there's no noreturn annotation on abort(). Does anyone know a reason for this? Is it a bug? ...

Const pointer in a class object-oriented bug

Hello I have a simple example below that does not compile. i get the following warrning about const Error message: error C2662: 'Cfoo::GetNum' : cannot convert 'this' pointer from 'const Cfoo' to 'Cfoo &' Conversion loses qualifiers class Cfoo { public: bool RunMe( const Cfoo * bar ) { int i = bar->GetNum()...

Questions regarding "warning C4312: 'type cast'"

This is the code I have: HWND WebformCreate(HWND hParent, UINT id) { return CreateWindowEx(0, WEBFORM_CLASS, _T("about:blank"), WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, 0, 0, 100, 100, hParent, (HMENU)id, GetModuleHandle(NULL), 0); } This is the warning I get: warning C4312: 'type cast' : conversion from 'UINT' to...

Is it possible to load a function into some allocated memory and run it from there?

I'm messing around with some interprocess communication stuff and I am curious if it's possible to copy a function into some shared memory and run it from there from either process. Something like: memcpy(shared_memory_address, &func, &func + sizeof(func)); I realize you can't take the size of the function but that was what popped in...

What is a good library for interfacing with audio files?

I need a library for loading audio samples from a file and creating new audio files given the audio samples, author name, title, etc. The 2 main audio file formats I'll be using are WAV and MP3. ...

Need to know how to check if the inputted string has terminated within a thread-safe logger in C++

I am very new at this and apologise if my question is not clear. I have created a thread safe logger in C++. This logger will be used in a large program & will be called from multiple places. I am using a singleton so there is only one instance of the logger. This logger outputs to a file & to the console. It behaves similar to cout; it...

Compiling a project (VS 2008) with the /p argument (preprocess to a file) doesn't compile

I have a project in c++ that I would like to view the preprocessor output to see what some #defines and macros would look like. I tried the /p switch to turn on the preprocess to a file option to the compiler (it turns off full compilation and only runs the preprocessor) but my project now refuses to compile and shows a long list of err...

RegOpenKeyEx returns 1

I can't catch this problem on my own comp, but "test users" keep informing about this. What is it? (HKEY_CURRENT_USER, handle is got by RegOpenCurrentUser) 1 = ERROR_INVALID_FUNCTION ...

Is this considered memory leak?

The general rule, only objects allocated in the free store can cause memory leaks. But objects created in the stack doesn't. Here is my doubt, int main() { myclass x; ... throw; ... } If throw is not handled, it calls, terminate(), which in turn calls abort() and crashes the application. At this tim...

QFutureWatcher::progressValue returns a positive integer, but the min/max are both zero

The QFuture is iterating over a bidirectional iterator, which I assume is the root of the problem. However, the docs say that QFutureWatcher::progressValue "returns a value between progressMinimum and progressMaximum". I am calling QtConcurrent::filtered like this: QtConcurrent::filtered(myMap.begin(), myMap.end(), filterFn). Does an...

resize a 4d vector

How can I resize a 4d vector in C++? ...

Comparison of Boost StateCharts vs. Samek's "Quantum Statecharts"

I've had heavy exposure to Miro Samek's "Quantum Hierarchical State Machine," but I'd like to know how it compares to Boost StateCharts - as told by someone who has worked with both. Any takers? ...

Baffling gcc complaint about usage of Qt4 setValidator

We're stumped as to why gcc complains about this line in our app: doubleFrom->setValidator(new QDoubleValidator(doubleFrom)); with these complaints: error: expected type-specifier before 'QDoubleValidator' error: expected `)' before 'QDoubleValidator' error: no matching function for call to 'QLineEdit::setValidator(int*)' candidates ...

C++ -fvisibility=hidden -fvisibility-inlines-hidden

I have a question about the C++ visibility attribute. I have read http://gcc.gnu.org/wiki/Visibility and yet I dont quite understand how it works. I want use the visibility to be hidden on some of my shared libraries I have. I believe this means that the symbols are hidden ? How are you meant to link the shared library then ? Is there ...

Group boxes and WS_CLIPCHILDREN

Group boxes don't render properly if the parent window has the WS_CLIPCHILDREN style set. My current workaround is to simply remove the flag from the parent. However this results in extreme flickering when resizing the window. Is there a better workaround possible? Update The Dr Dobbs article Resizable Dialogs Revisited address exactl...

Using ASM when compiling x64 C++ with MSVC10

Due to MSVC10 not allowing the use of inline ASM instructions when targeting x64 architecture, I'm looking for any ways to get around such restrictions. I have learned from googling that writing and compiling separate ASM modules then linking against them and calling them from C++ is one way, however I have no idea how I would do this. A...

use of rand() function to generate ascii values

int RandInt(int a, int b){ return (rand()%b+a); } I want to generate the random character values so i call it like this char asciiValue = RandInt(65, 90); but my output is not quite what i expect... am i doing something wrong? --edit put in wrong values for randint call, my bad ...