c++

Starting Game Dev in C++

I know the basics of C++, and I am currently working a bit with the Win32 API. I feel the next step I want to take is game development. I have looked around, and I have a basic idea of how I would get started, but I would like to see if any of you guys have resources or suggestions that will help me out. What I would really like to d...

Unresolved external symbol on static class members

Very simply put: I have a class that consists mostly out of static public members, so I can group similar functions together that still have to be called from other classes/functions. Anyway, I have defined two static unsigned chars in my class' public scope, when I try to modify these values in the same class' constructor, I am gettin...

What is the most elegant way to read a text file with c++?

Hi, I'd like to read whole content of a text file to a std::string object with c++. With Python, I can write: text = open("text.txt", "rt").read() It is very simple and elegance. I hate ugly stuff, so I'd like to know what is the most elegance way to read a text file with c++? Thanks. ...

Resources for i18n in C++

I'm playing around with the locale and i18n stuff in c++ and have been looking for real world examples. I've read through the Josuttis chapter on i18n in his book, and found it useful but with no real world examples to draw from I've no idea if I'm following best practices are committing beginner mistakes. What resources can stackoverflo...

__REQUIRED_RPCNDR_H_VERSION__

I create a header file from an IDL . The IDL file has been compiled in Visual C++ 2005 . The generated header file contains #define REQUIRED_RPCNDR_H_VERSION 475 . I tried to use this header file in Visual Studio 2003 , where rpcndr.h contains { #define RPCNDR_H_VERSION ( 450 ) // and #if ( RPC...

How do you mock classes that use RAII in c++

Here's my issue, I'd like to mock a class that creates a thread at initialization and closes it at destruction. There's no reason for my mock class to actually create and close threads. But, to mock a class, I have inherit from it. When I create a new instance of my mock class, the base classes constructor is called, creating the thre...

Why would waveOutWrite() cause an exception in the debug heap?

While researching this issue, I found multiple mentions of the following scenario online, invariably as unanswered questions on programming forums. I hope that posting this here will at least serve to document my findings. First, the symptom: While running pretty standard code that uses waveOutWrite() to output PCM audio, I sometimes ge...

Design: Large archive file editor, file mapping

Hello! I'm writing an editor for large archive files (see below) of 4GB+, in native&managed C++. For accessing the files, I'm using file mapping (see below) like any sane person. This is absolutely great for reading data, but a problem arises in actually editing the archive. File mapping does not allow resizing a file while it's being a...

switch case vs if else

I was wondering if there was any difference in the way the following code was compiled into assembly. I've heard that switch-case is more efficient than if else, but in this example I am not quite sure if that would be the case. if(x==1){ ... }else if(x==2){ ... }else{ ... } and switch(x){ case 1: ... break; case 2: ... break;...

Capture which step of an animated system cursor is being shown on Windows

I want to capture as a bitmap the system cursor on Windows OSes as accurately as possible. The provided API for this is to my knowledge GetCursorInfo, DrawIconEx. The simple chain of actions is: Get cursor by using GetCursorInfo Paint the cursor in a memory DC by using DrawIconEx. Here is how the code looks roughly. CURSORINFO Cur...

Spinlock Versus Semaphore!

What is the basic differences between Semaphores & Spinlock? & In what best situations or conditions, we can use these. ...

Coercing template class with operator T* when passing as T* argument of a function template

Assume I have a function template like this: template<class T> inline void doStuff(T* arr) { // stuff that needs to use sizeof(T) } Then in another .h filee I have a template class Foo that has: public: operator T*() const; Now, I realize that those are different Ts. But If I have a variable Foo<Bar> f on the stack, the only way ...

OSX lacks memalign

I'm working on a project in C and it requires memalign(). Really, posix_memalign() would do as well, but darwin/OSX lacks both of them. What is a good solution to shoehorn-in memalign? I don't understand the licensing for posix-C code if I were to rip off memalign.c and put it in my project- I don't want any viral-type licensing LGPL-i...

Can you write a block of c++ code inside C#?

I heard somewhere that you can drop down to C++ directly inside C# code. How is this done? Or did I hear wrong? Note: I do not mean C++ / CLI. ...

In C++ what are the benefits of using exceptions and try / catch instead of just returning an error code?

I've programmed C and C++ for a long time and so far I've never used exceptions and try / catch. What are the benefits of using that instead of just having functions return error codes? ...

How can I use covariant return types with smart pointers?

I have code like this: class RetInterface {...} class Ret1: public RetInterface {...} class AInterface { public: virtual boost::shared_ptr<RetInterface> get_r() const = 0; ... }; class A1: public AInterface { public: boost::shared_ptr<Ret1> get_r() const {...} ... }; This code does not compile. In visual stu...

list iterator not incrementable

I have an old project that was built using visual studio 2003 and I recompiled it with vs2005 recently. However, during runtime, I get the following error: list iterator not incrementable I traced the program to this function: void InputQueue::update() { list<PCB>::iterator iter; list<PCB>::iterator iterTemp; for(iter = b...

Idiomatic use of std::auto_ptr or only use shared_ptr?

Now that shared_ptr is in tr1, what do you think should happen to the use of std::auto_ptr? They both have different use cases, but all use cases of auto_ptr can be solved with shared_ptr, too. Will you abandon auto_ptr or continue to use it in cases where you want to express explicitly that only one class has ownership at any given poin...

How do I write a for loop that iterates over a CAtlMap selectively deleting elements as it goes?

I'm trying to do the following without too much special case code to deal with invalidated POSITIONs etc: What's the best way to fill in the blanks? void DeleteUnreferencedRecords(CAtlMap<Record>& records) { for(____;____;____) { if( NotReferencedElsewhere(record) ) { // Delete record _______; } ...

Getting notifications when the user tries sending an SMS

Hi, My application is implemented as a service (running under services.exe). I am adding a new feature which requires being notified when the user sends an SMS. I have tried using IMAPIAdviseSink, registering with both IMAPISession and IMsgStore, but I do not get any notifications. The other options I can see are to create a Short Mes...