c++

Why won't Direct3D recover after unplugging a monitor in Windows XP?

An interesting bug came up that I'm having no luck with. In a windowed Direct3D9 program using native code, I handle a device lost using something similar to the following: void MyClass::RecoverFromDeviceLost(LPDIRECT3DDEVICE9 deviceToRecover, D3DPRESENT_PARAMETERS devicePresentParams ) { HRESULT hr = deviceToRecover->TestCoopera...

"GetOrCreate" - does that idiom have an established name?

Ok, consider this common idiom that most of us have used many times (I assume): class FooBarDictionary { private Dictionary<String, FooBar> fooBars; ... FooBar GetOrCreate(String key) { FooBar fooBar; if (!fooBars.TryGetValue(key, out fooBar)) { fooBar = new FooBar(); fo...

How can I share data between C++ and Lua?

I have been looking for tutorials demonstrating how to share a C++ object with Lua using the API. Most tutorials just show how to export a class. I would like to start very simple and expose a variable (say int myVar = 5) in such a way that a change in Lua will be reflected in the C++ application. Does anyone know any good tutorials ar...

Is there any memory browser in QtCreator?

I can't find it. In the watcher window I can manually type memory addresses but I'd like to see bigger chunks of memory... If this doesn't exist, is there any other free memory mapper for the Mac (except for XCode and Eclipse)? Thanks, rui ...

Can C++ compilers optimize "if" statements inside "for" loops?

Consider an example like this: if (flag) for (condition) do_something(); else for (condition) do_something_else(); If flag doesn't change inside the for loops, this should be semantically equivalent to: for (condition) if (flag) do_something(); else do_something_else(); Only in the first case, the code might...

C++ enum by step

I'm trying to write the equivalent of an enum in C++ going in steps of eight instead of one, like enum { foo, bar = 8, baz = 16, }; There will be a lot of entries, new ones will be added at intervals, and for clarity they really want to be written in an order other than order of entry, so it would be nice not to have to ke...

What is the most elegant and efficient way to model a game object hierarchy? (design bothers)

I've got the following code, think simple shooter in c++: // world.hpp //---------- class Enemy; class Bullet; class Player; struct World { // has-a collision map // has-a list of Enemies // has-a list of Bullets // has-a pointer to a player }; // object.hpp //----------- #include "world.hpp" struct Object { virtual ~Object...

Is there a 'restart' function in Windows/C++

In a windows project I am working on, I intend to have a menu selection that copletely restarts the app. Is there a Windows or C++ function that does this? ...

Does Windows have its own 'call other .exe' function (C++)

I know in C++ there is a function system("example.exe"); that runs another program, put it requires the include stdlib.h. Because I am already including 'windows.h', is there an equivilant to the system() function in Windows? ...

Is it possible to prevent an RAII-style class from being instantiated "anonymously"?

Suppose I have an RAII-style C++ class: class StateSaver { public: StateSaver(int i) { saveState(); } ~StateSaver() { restoreState(); } }; ...to be used like so in my code: void Manipulate() { StateSaver save(1); // ...do stuff that modifies state } ...the goal being to enter some state, do stuff, then leave that sta...

C++: Pointer to class member function inside a non-related structure

I've done a bit of reading online as to how to go about this and I think I'm doing it correctly... My goal is to have an array of structure objects that contain pointers to member-functions of a class. Here's what I have so far... typedef void (foo::*HandlerPtr)(...); class foo { public: void someFunc(...); // ... private: ...

How to check for NULL in c++?

Hi, Let say for example, I have a struct, and an array of the struct. What I want to do is to iterate through the array and check if any of the item is a null. I tried checking the item against NULL and (struct *) 0, that don't seem to work. Is there any reliable way to check for null value? UPDATE Sample Code struct Test{ int a; }; ...

How can I use Dynamic Methods in C++

I've found myself writing some repetitious code in C++. I'm using some auto-generated, such that if I want to deal with Foo, Bar, & Baz they all have fairly similar method. E.g., get_foo, get_bar, get_baz, etc. For each "thing" I more or less have to do the same types of thing. Check if it exists, if it does, get the log, look for th...

C++ singleton vs. global static object

A friend of mine today asked me why should he prefer use of singleton over global static object? The way I started it to explain was that the singleton can have state vs. static global object won't...but then I wasn't sure..because this in C++.. (I was coming from C#) What are the advantages one over the other? (in C++) ...

C Bitwise, TRUNCATING zero's in hex. 0x15000000 -> 0x15 ??? HOW?

Hello all, Is this even at all possible? How would I truncate zeros? In the integer withOUT using any masking techniques (NOT ALLOWED: 0x15000000 & 0xff000000 like that.). And also WITHOUT any casting. ...

Thread Creation Problem

i have defined one thread fucntion inside .cpp file and i have called createThread function to create thread it is working fine.if i declare thread function declartion in .h file and definition in .cpp file means the thread is not executing immedialty the applcation quits.i'm creating a thread from main().what is the problem in this scen...

How can I get c-function based diffs?

Our team uses svn to manage our source. When performing a re-factor on a C file, I occasionally both change functions and move them within the file. Generally I try to avoid moving functions, because it makes the default svn diff get a bit addled about what's going on, and it often provides a diff which is more confusing than it needs to...

Using std::bind2nd with references

I have a simple class like this: class A { public: void f(const int& n) { std::cout<<"A::f()" << n <<"\n"; } }; and I am trying to use it like this: std::vector<A> vec; A a; vec.push_back(a); std::for_each(vec.begin(), vec.end(), std::bind2nd(std::mem_fun_ref(&A::f), 9)); But when I compile the code I get the follo...

Vc++ Error :Node is not a class or namespace

My Node.h is class Node{ private: int x; int y; public: Node(); Node(int x, int y); void setXX( int x); ..... } In Node.cpp I am doing: #include "Node.h" #include "stdafx.h" Node:: Node(){} Node:: Node(int x, int y){ this->x = x; this->y =y; } void Node::setXX(int x){ this->x = x;...

Storage Card Problem In windows mobile

Hi, I m making windows mobile application, it refers some DLL's but i have some problem here. Imagine my application is installed in storage card related DLL's present in Storage card only, if i launch application it refers some of DLL, now i will remove the storage card, still my application will be running,it will not quit only ultima...