c++

I want to start Qt development - what basic knowledge in C++ and OS do I have to own?

Hi, I'm going to learn Qt and I just want to know what parts of C++, OO design and other things I must have background in? Templates, RAII, Patterns, ....? ...

How can I shift elements inside STL container

I want to shift elements inside container on any positions to the left or right. The shifting elements are not contiguous. e.g I have a vector {1,2,3,4,5,6,7,8} and I want to shift {4,5,7} to the left on 2 positions, the expected result will be {1,4,5,2,7,3,6,8} Is there an elegant way to solve it ? ...

#ifdef in switch statement bug?

I have some code that looks like this: someFunc(value) { switch(value){ case 1: case 2: case 3: #ifdef SOMEMACRO case 4: case 5: #endif return TRUE; } return FALSE; } SOMEMACRO is defined, and let's say the value is 4.. Why does case 4 and 5 get skipped and FALSE is returned ...

decreasing cache misses through good design

How to decrease the number of possible cache misses when designing a C++ program? Does inlining functions help every time? or is it good only when the program is CPU-bounded (i.e. the program is computation oriented not I/O oriented)? ...

C++: Dll unloading issue

How can I ensure a dll is not unloaded while any objects in it exist? The problem is, when I was using explict memory management I could delete the dll objects before freeing the dll, however with smart pointers I have no controll over the order there destroyed, meaning the dll may be freed first causeing a crash when trying to free one...

Using std::for_each on polymorphic method in c++

When using the std::for_each, class A; vector<A*> VectorOfAPointers; std::for_each(VectorOfAPointers.begin(), VectorOfAPointers.end(), std::mem_fun(&A::foo)); If we have classes inheriting from A and implementing foo(), and we hold a vector of pointers to A, is there any way to call a polymorphic call on foo(), rather then explicitl...

for_each on a COM IEnumXxx interface?

I've got a COM object that returns an IEnumUnknown. Is there anything out there that'll turn it into an STL-style iterator? So that I can do something like this: IEnumUnkPtr pEnumUnk; // ...something that fills in pEnumUnk... MagicThing m(pEnumUnk); std::for_each(m.begin(), m.end(), DoSomethingWithUnk); ...or similar? ...

Where can I find the default icons used for folders and applications?

I'm trying to load the default HICON that explorer displays for: An open folder An exe that has no embedded default icon of its own. This can also be seen in 'Add/Remove Programs' or 'Programs and Features' as it's called on Vista. Do you know where these can be found? I think the folder icon might be in the resources of explorer.e...

C++ anonymous variables

Why wont this work? 0. #define CONCAT(x, y) x ## y 1. 2. #define VAR_LINE(x) \ 3. int CONCAT(_anonymous, __LINE__) = x 4. 5. #define VAR_LINE2(x) \ 6. int _anonymous ## x = 1 7. 8. int main() 9. { 10. VAR_LINE(1); 11. VAR_LINE(1); 12. VAR_LINE(1); 13. VAR_LINE2(__LINE__); 14. } The result from the a...

Viewing compiler expanded code - C++

I learned that compiler will expand macros while compiling. Templates are also expanded at the compile time. Is there any way to see this expanded code? I am compiling using Visual Studio 2008. any thoughts? ...

Security in programmming?

What is the best book to read about security issues that should be kept in mind while programming? What should a c++ programmer know about security? Is it worth buying any one of the following book If so which one should I get. Secure Coding In C & C++ Secure Programming Cookbook for C and C++ Writing Secure code ...

When to use virtual destructors?

Hi, I have a solid understanding of most OO theory but the one thing that confuses me a lot is virtual destructors. I thought that the destructor always gets called no matter what and for every object in the chain. When are you meant to make them virtual and why? ...

How to cast a pointer in C++

void foo(void **Pointer); int main () { int *IntPtr; foo(&((void*)IntPtr)); } Why do I get an error? error: lvalue required as unary ‘&’ operand Thanks ...

return statement vs exit() in main()

Should I use exit() or just return statements in main()? Personally I favor the 'return' statements 'cause I feel it's like reading any other function and the flow control when I'm reading the code is smooth (in my opinion). And even if I want to refactor the main() function, having 'return' seems like a better choice than exit(). Does ...

How to use BOOST_FOREACH with a boost::ptr_map?

How can I use BOOST_FOREACH efficiently (number-of-character/readability-wise) with a boost::ptr_map? Kristo demonstrated in his answer that it is possible to use BOOST_FOREACH with a ptr_map, but it does not really save me any typing (or makes my code really more readable) than iterating over the ptr_map with an iterator: typedef bo...

Using an asterisk in a RegExp to extract data that is enclosed by a certain pattern

Hi. I have an text that consists of information enclosed by a certain pattern. The only thing I know is the pattern: "${template.start}" and ${template.end} To keep it simple I will substitute ${template.start} and ${template.end} with "a" in the example. So one entry in the text would be: aINFORMATIONHEREa I do not know how many o...

Persistence solutions for C++ (with a SQL database)?

Hi, I'm wondering what kind of persistence solutions are there for C++ with a SQL database? In addition to doing things with custom SQL (and encapsulating the data access to DAOs or something similar), are there some other (more general) solutions? Like some general libraries or frameworks (something like Hibernate & co for Java and .N...

Dealing with "C compiler cannot create executables" in Cygwin

Whatever I try to compile in Cygwin I get the following output: checking for mingw32 environment... no checking for EMX OS/2 environment... no checking how to run the C preprocessor... gcc -E checking for gcc... gcc checking whether the C compiler (gcc ) works... no configure: error: installation or configuration problem: C compiler ...

What is the easiest way to convert a compressed wav file to an uncompressed wav file in C# or C++?

What is the easiest way to programatically convert a compressed wav file (MPEG codec for example, but could be any installed codec) to an uncompressed wav file (16 bit PCM)? I've heard that using direct show and writing the code in native C++ would do it, but I've not had much experience with direct show. Is there an easier way to do ...

Arduino C++ code: can you use virtual functions and exceptions?

Following up on this comment from the question Writing firmware: assembly or high level?: When compiling C++ code for the Arduino platform, can you use virtual functions, exceptions,etc. Or would you want to (have to) use a subset of C++ (as described in the comment) Any other caveats when programming for the Arduino platform? ...