c++

How do you check for infinite and indeterminate values in C++?

In my programs infinity usually arises when a value is divided by zero. I get indeterminate when I divide zero by zero. How do you check for infinite and indeterminate values in C++? In C++, infinity is represented by 1.#INF. Indeterminate is represented by -1.#IND. The problem is how to test if a variable is infinite or indeterminate. ...

Overriding an operator using const for both parameters in C++

Hi, I'm trying to create an overridden operator function using both const parameters, but I can't figure out how to do it. Here is a simple example: class Number { Number() { value = 1; }; inline Number operator + (const Number& n) { Number result; result.value = value + n.value; re...

What harm can come from defining BOOST_DISABLE_ABI_HEADERS when compiling boost?

What harm can come from defining BOOST_DISABLE_ABI_HEADERS when compiling boost? From the boost file: boost_1_37_0\boost\config\user.hpp // BOOST_DISABLE_ABI_HEADERS: Stops boost headers from including any // prefix/suffix headers that normally control things like struct // packing and alignment. //#define BOOST_DISABLE_ABI_HEADERS...

is it possible to detect pointer-to-member-function?

i want a specialize template in a pointer-to-member-function case. Is there a way to detect this? right now i declare struct isPtrToMemberFunc, then add an extra template (class TType=void) to each class (right now just 1) and specialize the extra template to see if its isPtrToMemberFunc. Is there a way to detect this automatically? if n...

Function with same name but different signature in derived class

I have a function with the same name, but with different signature in a base and derived classes. When I am trying to use the base class's function in another class that inherits from the derived, I receive an error. See the following code: class A { public: void foo(string s){}; }; class B : public A { public: int foo(...

C++, equivalence between pointer-to-functions and pointer-to-member-functions?

I'm used to thinking of member functions as just being a special case of normal functions, where member functions have an extra parameter at the beginning of their parameter list for the 'this' pointer, that is, the object on which the member function is supposed to act. I've used boost::function this way in the past and never encountere...

How can I find duplicate headers in a large solution in MSVC++ 2005 or 2008?

In Visual Studio (C++), is there a way to easily find duplicate headers that are defined in .cpp files? I'm also trying to find ways to detect this situation: A includes B includes C A includes C => A doesn't need to include C ...

Hudson, C++ and UnitTest++

Has anyone used Hudson as a Continuous-Integration server for a C++ project using UnitTest++ as a testing library? How exactly did you set it up? I know there have been several questions on Continuous Integration before, but I hope this one has a narrower scope. EDIT: I'll clarify a bit on what I'm looking for. I already have the buil...

Tutorial for tile based side scroller game-play?

Does anyone know a good resource or some pointers which could help me make a side scrolling tile based (descreet movement for character) with box pushing and moving platforms etc. I'm focused right now C/C++ console development (tho after this project I may stop and do stuff a little more graphical, still C/C++). Something bit like Super...

alternatives to winsock2 with example server source in c++

Hi, i'm using this example implementation found at http://tangentsoft.net/wskfaq/examples/basics/select-server.html This is doing most of what I need, handles connections without blocking and does all work in its thread (not creating a new thread for each connection as some examples do), but i'm worried since i've been told winsock wil...

Pointer to void in C++?

Hello, I'm reading some code in the Ogre3D implementation, and I can't understand what does a void*-typed variable could mean. What does a pointer to void means in C++? ...

How do I implement QHoverEvent in QT?

I'm just learning QT with C++. I have successfully implemented signals and slots to trap standard events like ButtonPushed(), etc. However, I want to have a function called when I mouse over and mouse out of a QLabel. It looks like QHoverEvent will do what I need, but I can't seem to find any tutorials or examples on how to implement thi...

What value does a Reference Variable in C++ store?

A pointer stores/is assigned a memory address; what about a reference variable? it stores the actual value of an object just like any other non-pointer simple variables on Stack? Thanks! ...

C++ Service Providers

Hi everyone, I've been learning C++, coming from C#, where I've gotten used to using service providers: basically a Dictionary<Type, object>. Unfortunately, I can't figure out how to do this in C++. So the questions are basically: How would I make a dictionary in C++. How would I use 'Type' with it, as far as I know there is no 'Type' ...

On writing win32 api wrapper with C++, how to pass this pointer to static function

I want to convert function object to function. I wrote this code, but it doesn't work. #include <iostream> typedef int (*int_to_int)(int); struct adder { int n_; adder (int n) : n_(n) {} int operator() (int x) { return x + n_; } operator int_to_int () { return this->*&adder::operator(); } }; int main(void...

a better way than casting from a base class to derived class.

I know downcasting like this won't work. I need a method that WILL work. Here's my problem: I've got several different derived classes all from a base class. My first try was to make an array of base class. The program has to select (more or less at random) different derived classes. I had tried casting from a base class to the derived c...

Read keyboard characters to determine shortcuts

I'm working on a document application and part of this application I've to add support to read the keyboard pressed events and replace the pre-defined characters set if that keyboard entry is match with the pre-defind short form/word.The actual application has implemented in C++. Please provide me your thoughts on how to implement this....

How do people get mixin-style re-use in C#?

I come from a C++ background where I can use template mixins to write code that refers to FinalClass which is a template parameter that is passed in. This allows reusable functions to be "mixed-in" to any derived class, by simply inheriting from ReusableMixin with a template paramter of MyFinalClass. This all gets inlined into the clas...

How to avoid a common bug in a large codebase?

Is there a way to undefine the += on strings and wstrings for chars and wchar_t? Basically I want to avoid bugs like the following: int age = 27; std::wstring str = std::wstring(L"User's age is: "); str += age; std::string str2 = std::string("User's age is: "); str2 += age; The above code will add the ascii character 27 to the stri...

Struct with boolean field default initialization?

I have the following use case, a struct with some boolean and int variables struct a { int field1; bool field2; bool field3; }; I am refactoring this code, and writing a constructor for the struct , the problem is the default initialization of fields. I am not criticizing any language construct here, but ideally I woul...