c++

Negator adaptors in STL

Hello! Consider following example: #include <iostream> #include <functional> #include <algorithm> #include <vector> #include <boost/bind.hpp> const int num = 3; class foo { private: int x; public: foo(): x(0) {} foo(int xx): x(xx) {} ~foo() {} bool is_equal(int xx) const { return (x == xx); } void...

Runtime-dynamic properties in QPropertyEditor

Hello, I am using the QPropertyEditor from Qt-Apps.org. is it possible to create a class with exposed Properties where the amount of properties is runtime-dynamic? So for example you have a class which represents a vector of floats with an arbitrary length which is not known at compile time. So you have a vector<float> myFloats; as ...

c2593 error (operator identifier is ambiguous) when compiling for x64 platform

I'm trying to compile a C++ project using Microsoft VisualStudio 2008. This particular project compiles fine if you use Win32 as target platform. If I try to compile the same project for the x64 platform I get a C2593 'operator identifier' is ambiguous error in this line: case 't': os_ << (size_t)path->rnode->char_type; break; An...

segmentation fault on pthread_mutex_lock

hey, sorry to be a bother, but I need help urgently. I searched for this before I posted this question. I'm getting a segmentation fault when I try to do pthread_mutex_lock(&_mutex). This is really odd, I'm not sure what might have caused it. I have initialized _mutex in the constructor with pthread_mutex_init(&_mutex,NULL). anythi...

Linux API to list running processes?

I need a C/C++ API that allows me to list the running processes on a Linux system, and list the files each process has open. I do not want to end up reading the /proc/ file system directly. Can anyone think of a way to do this? ...

is declaring a variable an instruction

Is declaring/assigning a variable in a high level language such as c++, an explicit instruction? e.g. x = 5; It would be handled by the loader, and treated as state information, correct? It is not an instruction, but a state object, as opposed to something like a for loop, which is an instruction, which makes it's way to the cpu ? ed...

One line class definition?

I'm updating some code and while I was working in a header, I came across the following line. . . . class HereIsMyClass; . . . That's it. It's just one line that precedes another, longer class definition. HereIsMyClass is in fact another class somewhere else, but I don't understand why this line is written here. What does it do? ...

What's the correct way to use printf to print a size_t?

Size_t is defined as an unsigned integer, but the size of it depends on whether you're on a 32 or 64-bit machine. What's the correct and portable way to print out a size_t? ...

Have You Started Using C++0x?

Most of the compilers already support C++0x. Have you started using C++0x or are you waiting for the definition of x? I have to do some refactoring of my code; should I start using the new features? ...

How to write a C++ template that accepts every class and class template?

Be forewarned: This question seems way more obvious than it actually is. I'd like to write a template that can accept any concrete class or template class as a template parameter. This might seem useless because without knowing whether the passed in T is templated or not you won't know how to use it. The reason I want this is so that I ...

Calculate float at compile-time using templates

Hi, I'm new to this whole Template Metaprogramming in C++ mess and I simply can't get this right. The scenario: For example, I've got fractions 2/5, 6/9,... I want to calculate the result of those fractions at compile-time and sort them later using that value at run-time. Is this even possible? Macros maybe? Edit: Thanks Naveen, but i...

How would you create a console application from an existing object oriented API?

I have: existing object oriented native code API (non GUI) GUI application that works with this API The goal: To create an additional console application that lets user do some set of workflows (similar to ones of the above GUI app) by typing commands. This app should be "stateful" - available commands and their results would depen...

Windows Mobile fails to uninstall

Testing my app on some WM Std 6.1 I found out that it fails to uninstall. I receive this error: “[app] was not completely removed. Do you want to remove it from the list of installed programs?" Checking my setup.dll I can tell that Uninstall_Init and Uninstall_Exit are being called each time but all the files stays (they are not locked...

Which libraries should a C or C++ newbie know?

I recommended my friend the libraries in the book Numerical Recipes. However, it seems that they are too challenging for him. I am not sure which libraries are the best for a newbie in C/C++. Which libraries should a C or C++ newbie know? ...

How do I programatically get the version of a dll or exe?

I need to get the product version and file version for a dll or exe using Win32 native APIs in C or C++. I'm not looking for the Windows version, but the version numbers that you see by right-clicking on a dll, selecting "Properties", then looking at the "Details" tab. This is usually a four-part dotted version number x.x.x.x. ...

Extend an existing API: Use default argument or wrapper function?

I have an existing method (or function in general) which I need to grow additional functionality, but I don't want to break any use of the method elsewhere in the code. Example: int foo::bar(int x) { // a whole lot of code here return 2 * x + 4; } is widely used in the codebase. Now I need to make the 4 into a parameter, but any cod...

Example usage where Lua fits much better than C/C++

I'm currently embedding Lua and using it as a glorified intelligent config file. However, I think I'm missing something since people rave about the uses of Lua. For example, I can easily explain why you might use shell scripting instead of C by showing this example (admittedly , boost regexp is overkill): #include <dirent.h> #include ...

how do I stop a C++ application during execution to debug into a dll?

Hi all, I have an application for which I do not have the code, and a dll for which I do have the code. I need to be able to debug into the dll, but lacking the source for the exe, how do I do this? The dll code is mfc c++; I believe that the main app is the same thing as well. I've tried doing a 'set target application' deal, where ...

Function pointer problem

I am trying to use a function pointer, but the 3 lines below just do not seem to want to cooperate... I'm getting error code C3867. Can you see what I'm doing wrong? In .h file void MyFunc(int, FILEINFO*(*)(FILEINFO*), FILEINFO*, int); The definition in the .cpp file void MyFunc(int number, FILEINFO*(*GetFiles)(FILEINFO*), FILEINF...

Visually marking conditional compilation

We have a large amount of C/C++ code that's compiled for multiple targets, separated by #ifdefs. One of the targets is very different from the others and it's often important to know if the code you're editing is compiled for that target. Unfortunately the #ifdefs can be very spread out, so it's not always obvious which code is compile...