c++

Should a function's comment include descriptions of work done by functions it calls?

Let's say I have a function called DisplayWhiskers() which puts some slashes and backslashes on the screen to represent an animal's whiskers like this: /// \\\. I might write a comment for this function along the lines of // Represents an animal's whiskers by displaying three // slashes followed by a space and three backslashes But ...

Disable Exceptions in BOOST?

I want to use boost::asio but I don't want boost to throw exceptions, because in my environment exceptions must not be raised. I've encountered BOOST_NO_EXCEPTIONS but the documentation says that callers of throw_exception can assume that this function never returns. But how can a user supplied function not return? What replacement fun...

IContextMenu3 HandleMenuMsg2 is never called

Hi, I'm trying to implement a shell extension that extends IContextMenu3 and IShellExtInit, and i'm inserting menu items using the method described in section "HBMMENU_CALLBACK method" (http://www.nanoant.com/programming/themed-menus-icons-a-complete-vista-xp-solution) but in my project the method HandleMenuMsg2 or the HandleMenuMsg is...

C++: do you (really) write exception safe code?

EH seems to be the current standard, and by searching the web, I can not find any novel ideas or methods that try to improve or replace it (well, some variations exist, but nothing novel). Though most people seem to ignore it or just accept it, EH has some huge drawbacks: exceptions are invisible to the code and it creates many, many po...

10 character id that's globally and locally unique

Hi there! I need to generate a 10 character unique id (SIP/VOIP folks need to know that it's for a param icid-value in the P-Charging-Vector header). Each character shall be one of the 26 ASCII letters (case sensitive), one of the 10 ASCII digits, or the hyphen-minus. It MUST be 'globally unique (outside of the machine generating the i...

Use a regular iterator to iterate backwards, or struggle with reverse_iterator?

I recently learned about the right way to work with reverse iterators in C++ (specifically when you need to erase one). (See this question and this one.) This is how you're supposed to do it: typedef std::vector<int> IV; for (IV::reverse_iterator rit = iv.rbegin(), rend = iv.rend(); rit != rend; ++rit) { // Use 'rit' if a rever...

Using AlphaBlend() and FillRect()

So, I'm using AlphaBlend() to copy a rectangle from one HBITMAP to another. It works, but there is a problem. Whenever I use the FillRect() function, the alpha values in the HBITMAP get slammed out to 0. Everytime. So I have to GetDIBits(), reset the alpha back to 255, and then SetDIBits(), after every call to the Win32 api functions...

Strange characters appear when using strcat function in C++

I am a newbie to C++ and learning from the MSDN C++ Beginner's Guide. While trying the strcat function it works but I get three strange characters at the beginning. Here is my code #include <iostream> #include <cstdio> #include <cstring> using namespace std; int main() { char first_name[40],last_name[40],full_name[80],space[1]; ...

binary '=': no operator found which takes a right-hand operand of type "Button *"

I've got a Menu class which is a singleton. It is now going to have three Button objects on it, m_Load, m_Save, m_New. I am calling their constructors in an Init() method like so: void Menu::Init() { Menu::m_Load = new Button(L"../Data/png/load.png"); Menu::m_Save = new Button(L"../Data/png/save.png"); Menu::m_New = new Bu...

importing c++ data types to haskell with ffi

hi, I'm writing a haskell wrapper for a c++ library and as much as I can import functions from the library to my haskell program, I have no clue how to import c++ data types. For instance I have a function which takes as a parameter a video::E_DRIVER_TYPE EDT_OPENGL type defined in some.h file, and as I said before I know how to import...

Design choice with a container class that several classes use

I have a class that wraps around a list called ExplosionGroup (previously called AllExplosions for reasons I'll explain) which is a list of 'Explosion's (another class). My original design choice, and what ran for awhile, was to have an ExplosionGroup in the 'Level' class that runs all the levels. Any classes (like ships or bosses) that...

How to implement class composition in C++?

If I understand correctly we have at least 2 different ways of implementing composition. (Implementation with smart pointers is excluded case for simplicity. I don't use STL almost and have no desire to learn it.) Let's have a look at Wikipedia example: class Car { private: Carburetor* itsCarb; public: Car() {itsCarb=new...

C++ Book for a Beginner

Possible Duplicate: The Definitive C++ Book Guide and List Hi everyone, I am a high school student looking for a good book on C++. I already know Java, and I have C++ for dummies, but that book doesn't really do a great job at explaining important things (such as pointers, Memory Managment, etc...). I wouldn't really call mysel...

C++ : When do I need a shared memory allocator for std::vector?

First_Layer I have a win32 dll written in VC++6 service pack 6. Let's call this dll as FirstLayer. I do not have access to FirstLayer's source code but I need to call it from managed code. The problem is that FirstLayer makes heavy use of std::vector and std::string as function arguments and there is no way of marshaling these types int...

ostringstream problem with int in c++

Hi, I would expect the following code to output hello5. Instead, it only outputs hello. It seems to be a problem with trying to output an int to the ostringstream. When I output the same directly to cout I receive the expected input. Using XCode 3.2 on Snow Leopard. Thanks! #include <iostream> #include <string> #include <sstream> usi...

boost.asio tcp sockets, Will asynchronous operations be ordered?

Hi all, If am am calling boost::asio::async_write/async_read directly after each other, will the data be ordered? Or do I need to wait on the callback before I am calling write/read again? Thanks in advance! ...

How to use boost::function_types::parameter_types with ClassTypeTransform

I have been toying with an example hpp provided in the boost library and I am trying to figure out how to use this parameter_types function correctly. From the boost doc, parameter_types needs a ClassTypeTransform in order to parse class member function signatures. I want to parse member function signatures, but I cannot find any doc...

Why doesn't this compile?

When I try to declare iss using the first form, g++ gives me "error: no match for 'operator>>' in 'iss >> s'". But don't the two different declarations do the same thing? #include <iostream> #include <sstream> #include <string> int main() { const char *buf = "hello world"; std::string ss(buf); //std::istringstream iss(std:...

Combine native DLL and assembly into a single DLL

I am currently programming in C++ and C#. Using native C++ for the numerical computing part. Originally I intended to use C++/CLI to make a wrapper to the native C++ classes, but I found it would result in a 2 to 4 times slowdown. So I decided to compile my native C++ to a DLL and call in .NET/C# via P/Invoke. I will do data preproces...

Is assert evil?

The Go language creators write: Go doesn't provide assertions. (...) Programmers use them as a crutch to avoid thinking about proper error handling and reporting. What is your opinion about this? ...