c++

Head First's Design Patterns

Is Head First's Design Patterns book suitable for someone with an intermediate knowledge of C++ and no knowledge whatsoever of Java? Thanks. ...

C++ State machine affecting "HAS-A Parent"

I'm trying to implement a State Machine. The State Machine will have to have an impact on the object that "HAS" it as a member. However, I obviously can't include the "StateMachine" in the "Game" class AND include the "Game" header in the "StateMachine" class. How do I get around this problem? ...

Discriminating between typedefs to same type in c++

I want functionality similar to the below: typedef int A; typedef int B; struct foo { foo(A a) { /*specific to type A*/ } foo(B b) { /*specific to type B*/ } }; I use the typedefs in my program to denote logically different usage of the same type. So, I would like to create object of type foo differently for different typedefs. ...

What Design Pattern to use?

The problem to model is this: A hierarchy of levels within an Army, starting with the national army in whole, through field armies, subunits, and eventually the individual men. Each level may involve links to one or more other classes such as General or Officer or whatever. The units within say a field army need to be able to communicat...

data from a std::vector reference becomes corrupt after return from function call

I have a std::vector< tr1::shared_ptr<mapObject> > that I'm trying build from data contained in a compressed file. Here's the function I'm attempting to do that with: using std::tr1::shared_ptr; template<typename T> void loadSharedPtrVector(std::vector< shared_ptr<T> >& vect, TCODZip& zip) // the TCODZip is the compres...

Embedding v8 with Visual C++ 2010

Hi I'm trying to embed the v8 engine to my C++ application. I use Visual C++ 2010. I've built it successfully using this command: scons env="INCLUDE:C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include;C:\Program Files\Microsoft Visual Studio 10.0\VC\include,LIB:C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib;C:\Program Files\Micros...

C++ Prime number task from the book

I'm a C++ beginner ;) How good is the code below as a way of finding all prime numbers between 2-1000: int i, j; for (i=2; i<1000; i++) { for (j=2; j<=(i/j); j++) { if (! (i%j)) break; if (j > (i/j)) cout << i << " is prime\n"; } } ...

Does destructor of a C++ class that throws an exception gets called?

Suppose I have a class like this: #include <iostream> using namespace std; class Boda { private: char *ptr; public: Boda() { ptr = new char [20]; } ~Boda() { cout << "calling ~Boda\n"; delete [] ptr; } void ouch() { throw 99; ...

Understanding Google V8's Architecture

I'm not sure I understand V8's architecture (yes, I've read its documentation). In C# with the v8sharp wrapper I write something like this, for example: namespace App { class Point { public Point() { } public Point(double x, double y) { this.X = x; this.Y = y; } public d...

Subclass another application's control?

Is it possible to subclass another application's control so that my application could do something before the other application executes it's code and receiving the lParam and wParam? Ex: subclassing notepad's Edit control and when the user types, being able to know what the user typed? would SetWindowSubclass work if I provide the hWnd ...

Multi-Index Insert Failure Return (Boost)

I'm currently using Boost's multi-index to help keep track of how many times a packet passes through a system. Each time a system touches the packet, its IP address is added to a string, separated by commas. I go through that string then, tokenize it and add each IP found to a multi-index. Since the IPs are set to be unique right now, ...

C++ iostreams question

Hello! I have the following question on boost::iostreams. If someone is familiar with writing filters, I would actually appreciate your advices / help. I am writing a pair of multichar filters, that work with boost::iostream::filtering_stream as data compressor and decompressor. I started from writing a compressor, picked up some algor...

[DirectSound] Playback "clicking" noise

Hi, I am trying to write a program to play a small .wav file in C++. I have programmed it following the DirectX SDK documents to write and play on a secondary static buffer. It runs correctly except that at the end of the playback for any .wav file, there is a very noticeable "clicking" noise. I am certain that it's not a defect on my au...

__COUNTER__ equivalent on Xcode?

Hi! I am migrating a project from Linux to Xcode and I encountered a "version" problem.. I need a unique identifier at compile time for my dynamic stuff, on linux I was using the __ COUNTER__ preprocessor, but it seems that the gcc 4.2 used in Xcode doesn't know about __ COUNTER__ yet... So, I was wondering what I could do to solve th...

Should Display Lists be cpu intensive?

My application is rendering about 100 display lists / second. While I do expect this to be intensive for the gpu, I don't see why it brings my cpu up to 80 - 90 %. Arn't display lists stored in the graphics card and not in system memory? What would I have to do to reduce this crazy cpu usage? My objects never change so that's why im usin...

What is wrong with this use of offsetof?

I'm compiling some c++ code in MinGW GCC 4.4.0, and getting warnings with the following form... warning: invalid access to non-static data member '<membername>' of NULL object warning: (perhaps the 'offsetof' macro was used incorrectly) This problem seems familiar - something I've tried to resolve before and failed, I think, but a wh...

how to rotate a bitmap image in c++ using MFC?

how to rotate a bitmap image in c++ using MFC? i dont wanna use GDI. is it possible by only changing x and y values in this code? CBitmap img; CDC dc; BITMAP bmp; img.LoadBitmapW(IDB_BITMAP1); img.GetBitmap(&bmp); CDC* pDC = this->GetDC(); dc.CreateCompatibleDC(pDC); CBitmap* pOld = dc.SelectObject(&img...

Member offset macro - need details

Please take a look at this macro. It is used in Symbian OS SDK, which compiler is based on GCC (< 4 version of it). #ifndef _FOFF #if __GNUC__ < 4 #define _FOFF(c,f) (((TInt)&(((c *)0x1000)->f))-0x1000) #else #define _FOFF(c,f) __builtin_offsetof(c,f) #endif #endif I understand that it is calculating offset to specif...

Thinking in C++?

The programming language I use has been Java. I've been transitioning to C++ which has been somewhat rocky. The "rocky-ness" isn't in the learning but more along the lines of "Thinking in C++". I've seen many people say that you should learn C first (I technically know it already), and then I see people say no skip C and go straight to...

How to perform edge detection of a bitmap using MFC?

How do I perform edge detection of a bitmap using MFC? I have searched, but I found processes that contained matrices which I could not understand. ...