c++

Implementing z-axis in a 2D side-scroller

Hello, I'm making a side scroller similar to Castle Crashers and right now I'm using SAT for collision detection. That works great, but I want to simulate level "depth" by allowing objects to move up and down on the screen, basically along a z-axis (like this screenshot http://favoniangamers.files.wordpress.com/2009/07/castle-crashers-...

Keyboard Tabbing Stops working on Windows GUI

I have a windows gui built in Microsoft Visual C++ and when the user performs a certain set of actions the keyboard tabbing to move from widget to widget stops working. Simply put, there are two list boxes with an add and a remove buttons. Selecting a row in listbox #1 and pressing the add button removes the object from list box #1 and ...

Is It Possible To Simplify This Branch-Based Vector Math Operation?

I'm trying to achieve something like the following in C++: class MyVector; // 3 component vector class MyVector const kA = /* ... */; MyVector const kB = /* ... */; MyVector const kC = /* ... */; MyVector const kD = /* ... */; // I'd like to shorten the remaining lines, ideally making it readable but less code/operations. MyVector ...

Installing LEX/YACC or flex/bison on Windows, Visual C++ 2008

There's too much bytes and too few information in Internet, so I decided to ask if someone have already done such an installation. How to compile/where to download binaries? Where can I find a build rule? Where can I find a bunch of good samples (with associativity resolution, symbol tables etc.)? ...

Really big number

First of all apologies if there is already a topic like this but I have not found... I need to know how to handle a really big number such as the result of 789^2346: #include <iostream> #include <cmath> using namespace std; int main () { cout << pow(789,2346) << endl; } ...

OpenGL and GLUT in Eclipse on OS X

I have been trying to setup the OpenGL and GLUT libraries in Eclipse, with CDT, on OS X with not very much success. I cannot seem to get eclipse to actually realize where GLUT is. It is currently giving me the error that I have an unresolved inclusion GL/glut.h. Looking around online I found that I should be using the -framework GLUT fla...

Usefulness of const (C++)

I'm a const fiend, and I strive to make everything as const as possible. I've tried looking at various dissassembly outputs from const and non const versions of functions, and I've yet to see a marked improvement however. I'm assuming compilers nowadays are able to do smart things with non const functions that could technically be cons...

Coding Linux console application in Visual C++ 2008/2010 Express

I was told about the fascination of C++ and I have recently downloaded Visual C++ IDE to start learning C++. However I had this question in mind: How can I write C++ console application in Visual C++ and build it for Linux and Windows? Is there any plugin, additional compilers or hacks to go around with? ...

Template deduction and function pointers

How does the compiler know the correct type for this code: class Base { protected: typedef View * ViewType; typedef boost::function<ViewType ()> ActionType; typedef boost::unordered_map<std::string, ActionType> ActionMapType; ActionMapType actions; template <class ControllerType> inline void addAction(std::st...

Using Boost with Team Foundation Server

What would be a good way to use Boost in a small team (< 10 people) and lower the time between joining the team and building the application as much as possible. I basically want a workflow like this... Set up the TFS with the new person's username + password. Have them log into the TFS from Visual Studio. Check out the team project (w...

Read a line from file, using stream style

Hi, I have a simple text file, that has following content word1 word2 I need to read it's first line in my C++ application. Following code works, ... std::string result; std::ifstream f( "file.txt" ); f >> result; ... but result variable will be equal to "word1". It should be equal to "word1 word2" (first line of text file) Yes, i ...

Using boost test with Visual Studio

I am trying to use Boost Test to add some much needed unit tests to my code. However I can't seem to get it to work. Right now I have the following code #include <Drawing.h> #define BOOST_AUTO_TEST_MAIN #define BOOST_TEST_MODULE DrawingModelTests #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_SUITE(DrawingModelTests) BOOST_AUTO_T...

How to debug using gdb?

I am trying to add a breakpoint in my program using b {line number} but I am always getting an error that says: No symbol table is loaded. Use the "file" command. What should I do? ...

How to get a "bus error"?

I am trying very hard to get a bus error. One way is misaligned access and I have tried the examples given here and here, but no error for me - the programs execute just fine. Is there some situation which is sure to produce a bus error? ...

Multiply without * operator

I was just going through some basic stuff as I am learning C. I came upon a question to multiply a number by 7 without using * operator. Basically its like this (x<<3)-x; Now I know about basic bit manipulation operations, But I cant get how do you multiply a number by any other odd number number without using * operator?? Is th...

C++ linker errors, Undefined references to Items that should be referenced from a Share Object

I am building a library, called physgameengine, to aid in building games. This game library links against several libraries, including: Ogre3d, Bullet Physics and SDL, which are in the library files libOgreMain-1.6.5.so, libBulletCollision.a, libBulletDynamics.a, libBulletSoftBody.a, libSDL-1.2.so.0. This Library/Shared object appears to...

SFINAE canAdd template problem

I'm trying tow write a SFINAE template to determine whether two classes can be added together. This is mostly to better understand how SFINAE works, rather than for any particular "real world" reason. So what I've come up with is #include <assert.h> struct Vec { Vec operator+(Vec v ); }; template<typename T1, typename T2> struct Ca...

Getting Machine's MAC Address -- Good Solution?

I've heard it's not possible with my current library of winpcap. Is this really true? I see lots of examples on the net but then comments saying "This doesn't work". What's the best way to get a MAC address of the local machine? ...

Compact pointer notation with doubles

Quick question. When you are accessing a character array, I know you can set the pointer to the first element in the array, and use a while look and do something like while (*ptr != '\0') { do something } Now is there a double or int equivalent? #define ARRAY_SIZE 10 double someArray[ARRAY_SIZE] = {0}; double *ptr = someArray;...

Can you tell me why this generates time limit exceeded in spoj(Prime Number Generator)

#include<iostream> #include<string.h> #include<math.h> using namespace std; bool prime[1000000500]; void generate(long long end) { memset(prime,true,sizeof(prime)); prime[0]=false; prime[1]=false; for(long long i=0;i<=sqrt(end);i++) { if(prime[i]==true) { for(long long y=i*...