c++

C++ Forward Declaring a class?

In a .h if I have: #pragma once #include <xxxx.h> #include "yyyy.h" class AAAAAA; class BBBBBB; class ZZZZZZ { public: // etc }; using class AAAAAA; is forward declaring a class right? Why would one do this? Is it needed? What are the benefits? Drawbacks? ...

A tool to tell you what source files are needed in a C++ project?

I am porting a large, messy, 10 year old cold base in C++ from Metrowerks on OS X to XCode. There are so many files and all the other people that touched this over the years are gone. Nobody know what files are actually needed and which are just cruft. Is there any tool that I could run and have it produce a list of what files are ACTUA...

Removing volatile nature using const_cast

Hi, I heard that volatile nature of a variable can be removed using const_cast operator. In which scenarios we need to remove volatile nature of a variable ? are there any good use cases ? Is it dangerours operation, because we declared it as volatile thinking that it would be modified by external factors and removing volatile nature co...

Best C++ compiler and options for windows build, regarding application speed?

I am making a game for windows, mac and GNU, I can built it on windows already with MSVC and MingW... But I am not finding good information regarding how much compilers optmize. So what compiler, and options on that compiler, I can use to make my Windows version blazing fast? Currently the profilers are showing some worring results l...

c++ calling non-default constructor as member

hello, let's say i have a class A and a class B. B is used as a member in A. B does not have a default constructor but one that requires a parameter. class B { B(int i) {} }; class A { B m_B; A() { m_B(17); //this gives an error } }; how can i still use B as a member in A? ...

Productivity tools for C & C++ software development

In this day and age of advanced IDEs with plethora of functions, what tools you wish you had in your software development tool box to accelerate your day to day C & C++ software development? Please list the tools you wish you had but did not have time to code for yourself. For instance, it would be nice to have a tool to check if a parti...

Mixing assembler code with c/c++

Why is assembly language code often needed along with C/C++ ? What can't be done in C/C++, which is possible when assembly language code is mixed? I have some source code of some 3D computer games. There are a lot of assembler code in use. ...

How do flags work in c?

Ok I want to add some sort of flag like variable to one of my classes and had some questions about going about doing it. After looking at some source that uses it I noticed some stuff like this. TEXTUREFLAGS_POINTSAMPLE = 0x00000001, TEXTUREFLAGS_TRILINEAR = 0x00000010, Does the way this work is by combining all the flags into one int...

iterator for map - problem with searching

hello i got an iterator running on a multimap ,my multimap includes two fields the first 1 is the key value which is a string Lastname and the second 1 is the data which is a pointer to an object called Employee. in my program i need to be able to find an element inside my map using iterator (cause i am trying to find the data by its ID ...

Trapping the mouse?

I'm using GLUT and developing a FPS game. I need a way to trap the mouse so that the camera continues to move because right now when the mouse position exceeds the monitor limit, there is no way to calculate change in X or change in Y. How can I 'trap' the mouse with GLUT? Thanks ...

which is faster, and which is more flexible: printf or cout?

Possible Duplicates: printf vs cout in C++ cin or printf?? I've always wondered about printf and cout.. which one is ultimately faster, and is it the most flexible as well (ie can print a range of variables, and output can be formatted)? P.S. I know this looks similar to http://stackoverflow.com/questions/2872543/printf-vs-...

Problem with the compiling of the STLport under Snow Leopard

I am trying to build the latest version of stlprot under Snow Leopard. Steps for the compiling i have made: ./configure sudo make && make check make && make check are working fine. the problem occurs, if i call 'sudo make install', i get an error: /bin/sh: /usr/local/include/stlport: No such file or directory Can't create /usr/loca...

How to check if my iterator stands on nothing

Hello, i'm using a multimap stl, i iterate my map and i did'nt find the object i wanted inside the map, now i want to check if my iterator holds the thing i wanted or not and i'm having difficulties with it because it's not null or something. thanx! ...

C++ synchronization guidelines

Does anyone know of a decent reference for synchronization issues in C++? I'm thinking of something similar to the C++ FAQ lite (and the FQA lite) but with regards to concurrency, locking, threading, performance issues, guidelines, when locks are needed and when they aren't, dealing with multithreaded library code that you can't control,...

Pointer to Array of Struct

struct bop { char fullname[ strSize ]; char title[ strSize ]; char bopname[ strSize ]; int preference; }; int main() { bop *pn = new bop[ 3 ]; Is there a way to initialize the char array members all at once? Edit: I know I can use string or vector but I just wanted to know out of curiosity. ...

How to write an elegant collision handling mechanism?

I'm in a bit of a pickle: say I'm making a simple, 2D, Zelda-like game. When two Objects collide, each should have a resulting action. However, when the main character collides with something, his reaction depends solely on the type of the object with which he collided. If it's a monster, he should bounce back, if it's a wall, nothing sh...

.NET: Inheritance Modify Base Class (C++ Conversion)

I have two classes. The base class is A. The inherited class is B. I would like copy a base class from one object into the base class of another object without affecting the original class. However, .NET seems to ignore the copying. Is this not possible in .NET. I know this is possible in C++. I have included C++ code to illustrate what ...

Downloadable STL documentation that covers TR1?

For my offline coding needs, I've been using the downloadable STL documentation from SGI. Unfortunately it was last edited in 1999, and doesn't cover any of the TR1. It's easy enough to find online references for TR1, but can anybody recommend an easily downloadable TR1 reference for working offline? In HTML? I've downloaded Boost's ...

Numerical Error in simple CUDA code

I just started experimenting cuda with the following cude #include "macro.hpp" #include <algorithm> #include <iostream> #include <cstdlib> //#define double float //#define double int int RandomNumber(){return static_cast<double>(rand() % 1000);} __global__ void sum3(double const* a, double const* b, double c...

Are there tools that help organizing #includes?

Are there any tools that help organizing the #includes that belong at the top of a .c or .h file? I was just wondering because I am reorganizing my code, moving various small function definitions/declarations from one long file into different smaller files. Now each of the smaller files needs a subset of the #includes that were at the ...