c++

Simple efficiency question C++ (memory allocation)..and maybe some collision detection help?

I'm writing a little arcade-like game in C++ (a multidirectional 2d space shooter) and I'm finishing up the collision detection part. Here's how I organized it (I just made it up so it might be a shitty system): Every ship is composed of circular components - the amount of components in each ship is sort of arbitrary (more components, ...

How to design a simple C++ object factory?

In my application, there are 10-20 classes that are instantiated once[*]. Here's an example: class SomeOtherManager; class SomeManagerClass { public: SomeManagerClass(SomeOtherManager*); virtual void someMethod1(); virtual void someMethod2(); }; Instances of the classes are contained in one object: class TheManager { pub...

C++ Object Instantiation

Hi all, I'm a C programmer trying to understand C++. Many tutorials demonstrate object instantiation using a snippet such as: Dog* sparky = new Dog(); which implies that later on you'll do: delete sparky; which makes sense. Now, in the case when dynamic memory allocation is unnecessary, is there any reason to use the above inste...

C++/Win32: How to get the alpha channel from an HBITMAP?

I have an HBITMAP containing alpha channel data. I can successfully render this using the ::AlphaBlend GDI function. However, when I call the ::GetPixel GDI function, I never get back values with an alpha component. The documentation does say that it returns the RGB value of the pixel. Is there a way to retrieve the alpha channel valu...

SetWindowsHookEx, KeyboardProc and Non-static members

I am creating a keyboard hook, wherein KeyboardProc is a static member of a class CWidget. class CWidget { static LRESULT CALLBACK KeyboardProc(int code, WPARAM wParam, LPARAM lParam ); }; I want to call the non-static members of CWidget inside the CWidget::KeyboardProc. What is the best way to do it? KeyboardProc does not hav...

Best C++ Book for a Java Programmer with C and Python Experience

I've programmed in Java for 2 years and I'm very good at it. I've also done Python and C for 4 months each and I did fine. I understand the C concepts and syntax well now. I'm reading Bjarne Stroustrup's "The C++ Programming Language" but the book is big and seems like it will take some good time to read it from cover to cover though I'...

In C++ why have header files and cpp files?

I often wondered: why does C++ have header files and cpp files? ...

Why didn't header files catch on in other programming languages?

Based on the response to this question: Why does C++ have header files and CPP I have seen the responses and understand the answers - so why didn't this catch on? C# Java? ...

How to use dependencies of C++ libs in Visual Studio regarding the header path

We have several C++ libs that are used in applications and so many dependencies occur. Example problem: Lets say we have an application AppA that uses libB and libC. libC uses libD. Each lib is a static library project, all libs are grouped in a solution and the dependencies are given to Visual Studio, so all libraries and the appli...

Polyphonic sound playback

I need audio playback with these features: good performance (for game), pitch control, and ability to layer the same sample multiple times at the same time (polyphony). What would be a quick way to get this on the iphone sdk? Here's what I found out so far: There's no available libraries or sample code that does this, please show me ...

Get active window without global hooks or polling GetActiveWindow?

How can I get notifications about what is the currect active window and when this changes without polling GetActiveWindow or using global hooks? I don't like polling, and I'm working in C# and global hooks don't work (mostly). ...

understanding dll dependencies

I'm building a c++ DLL in visual studio 2008. For some reason, even when I build in release mode, my dll still depends on msvcr90d.dll. I can see that using depends.exe Is there any way to figure out what is causing this dependency? My run-time library setting is /MD Thanks, Dan ...

Symbian C++ - Substring operations on descriptors

Hi What is the preferred/easiest way to manipulate TDesC strings, for example to obtain a substring. I will give you an example of my scenario. RBuf16 buf; ... CEikLabel label; ... label->SetTextL(buf); // (SetTextL takes a const TDesC&) I want to get a substring from buf. So do I want to manipulate the RBuf16 directly and if so wha...

Exception elimination in C++ constructors

We have recently been faced with the problem of porting our C++ framework to an ARM platform running uClinux where the only vendor supported compiler is GCC 2.95.3. The problem we have run into is that exceptions are extremely unreliable causing everything from not being caught at all to being caught by an unrelated thread(!). This seems...

Calling NT function on pre-NT system

So I don't do a lot of Win32 calls, but recently I have had to use the GetFileTime and SetFileTime functions. Now although Win98 and below are not officially supported in my program people do use it there anyway, and I try to keep it as usable as possible. I was just wondering what will happen as those functions do not exist in pre-NT sy...

Implementing event conditions in a C++ state machine

I'm using an hierarchical FSM for an embedded C++ application interface. I'd like to use small functions to determine whether certain inter-state events can be triggered, as well as use them to effect changes in the database: however, making a new class with different event functions for each state is daunting, as well as setting pointer...

Are goto and destructors compatible?

This code leads to undefined behavior: void some_func() { goto undefined; { T x = T(); undefined: } } The constructor is not called. But what about this code? Will the destructor of x be called? I think it will be, but I want to be sure. :) void some_func() { { T x = T(); goto out; } out: } ...

Do parameter or return type implicit conversions take priority in C++?

If I have the code: int f(int a) { return a; } double f(double g) { return g; } int main() { int which = f(1.0f); } Which overload of f is called, and why? ...

Are there benefits of passing by pointer over passing by reference in C++?

Are there benefits of passing by pointer over passing by reference in C++? Lately, I have seen a number of examples that pass the a pointer instead of passing by reference. Are there benefits to doing this? Example: func(SPRITE *x); with a call of func(&mySprite); vs. func(SPRITE &x); with a call of func(mySprite); ...

Must default function parameters be constant in C++?

void some_func(int param = get_default_param_value()); ...