c++

C++ need for Assembly in embedded systems

I hear of a need to call assembly functions/calls when programming embedded systems in C. Is this necessary in C++ or not? ...

System-wide ShellExecute hooks?

Hello, is there any way I can install a system-wide ShellExecute hook using C++ without having to inject a hooking module into every active process. I am using Windows 7. My purpose for this is because, I want to be able to select which browser a link is opened in when a link is opened with the default browser using ShellExecute, like th...

Where to get custom Visual Studio 2008 syntax highlighting (complex one)

Ok, im used to see some more syntax highlighting, and the default syntax highlighting is really limited in VS 2008, so i was thinking, is there such highlighting somewhere: defined variables would have own color. defined functions would have own color. predefined functions would have own color (from libs etc, would have own list for th...

How are game event lengths handled in 2D games

I have an idea of how I want to approach this but i'm not sure if it is ideal. By event I mean for example, if the player wins, a bunch of sparks fly for 1 second. I was thinking of creating my game engine class, then creating a game event base class that has 3 void functions, update, draw, render. There could be for example fireforks fo...

C / C++ How to copy a multidimensional char array without nested loops?

I'm looking for a smart way to copy a multidimensional char array to a new destination. I want to duplicate the char array because I want to edit the content without changing the source array. I could build nested loops to copy every char by hand but I hope there is a better way. Update: I don't have the size of the 2. level dimension...

What is the sprintf() pattern to output floats without ending zeros?

I want to output my floats without the ending zeros. Example: float 3.570000 should be outputted as 3.57 and float 3.00000 should be outputted as 3.0 (so here would be the exception!) ...

Why does the following class have a virtual table?

Suppose I have a diamond inheritance situation as follows: class A{ public: virtual void foo(){}; }; class B: public virtual A{ public: virtual void foo(){}; }; class C: public virtual A{ public: virtual void foo(){}; }; class D: B, C{}; The last line yields a compilation error citing ambiguity. As I understand it, the pr...

C++ decimal output formatting

Hi, i'm writing a double value to a file. The numeric value is written with a point as a decimal separator. I would like to use a comma. How i can do that? ...

How to allow derived class to call methods on other derived class? OO-design

Say I have something like -- this is just an example mind you. class Car { void accelerate(); void stop(); } class Person { void drive(Car car); } class Toyota : public Car { void accelerateUncontrollably(); } class ToyotaDriver : public Person { void drive(Car car) { // How to accelerateUncontrollably without...

One Valid Case of Exception leaving a Destructor

I'm working on a simple class to manage the lifetime of a HKEY. class Key { HKEY hWin32; public: Key(HKEY root, const std::wstring& subKey, REGSAM samDesired); Key(const Key& other); ~Key(); Key& operator=(const Key& other); Key& swap(Key& other); HKEY getRawHandle() { return hWin32; }; }; //Other Methods.....

How to know if the the value of an array is composed by zeros?

Hey, if you can get a more descriptive tittle please edit it. I'm writing a little algorithm that involves checking values in a matrix. Let's say: char matrix[100][100]; char *ptr = &matrix[0][0]; imagine i populate the matrix with a couple of values (5 or 6) of 1, like: matrix[20][35]=1; matrix[67][34]=1; How can I know if the bi...

Bus Error Upon Calling Delete (C++)

I've been creating a class that takes a bunch of images and overlays them onto one BMP. For some reason upon running the code I'm getting a segfault and I've tracked it down to this method. Essentially the if statement checks to see if there is a valid index in the array of images to place this new image in. If it is valid then it del...

Embedded C++ : to use exceptions or not?

I realize this may be subjective, so will ask a concrete question, but first, background: I have always been an embedded software engineer, but usually at Layer 3 or 2 of the OSI stack. I am not really a hardware guy. I have generally always done telecoms products, usually hand/cell-phones, which generally means something like an ARM ...

Embedded C++ : to use STL or not?

I have always been an embedded software engineer, but usually at Layer 3 or 2 of the OSI stack. I am not really a hardware guy. I have generally always done telecoms products, usually hand/cell-phones, which generally means something like an ARM 7 processor. Now I find myself in a more generic embedded world, in a small start-up, where ...

Is it possible to create and initialize an array of values using template metaprogramming?

I want to be able to create an array of calculated values (let's say for simplicity's sake that I want each value to be the square of it's index) at compile time using template metaprogramming. Is this possible? How does each location in the array get initialized? (Yes, there are easier ways to do this without resorting to template m...

Not Able To Use STL's string class

Encountered this problem before but forgot how I solved it. I want to use the STL string class but the complier is complaining about not finding it. Here is the complete .h file. #ifndef MODEL_H #define MODEL_H #include "../shared/gltools.h" // OpenGL toolkit #include <math.h> #include <stdio.h> #include <string> #include <iostream> ...

How do you use sets and gets in C++?

I've used them in java and didn't seem to have too many issues, but I'm not grasping them very well in C++. The assignment is: Write a class named Car that has the following member variables: year. An int that holds the car's model year. make. A string that holds the make of the car. speed. An int that holds the car's curr...

Creating multicast events with std::tr1::function (or boost::function)

I'm attempting to create C#-like multicast delegates and events using features from TR1. Or Boost, since boost::function is (mostly) the same as std::tr1::function. As a proof of concept I tried this: template<typename T1> class Event { private: typedef std::tr1::function<void (T1)> action; std::list<action> callbacks; public: inli...

How To Create File System Fragmentation?

Risk Factors for File Fragmentation include mostly full Disks and repeated file appends. What are other risk factors for file fragmentation? How would one make a program using common languages like C++/C#/VB/VB.NET to work with files & make new files with the goal of increasing file fragmentation? WinXP / NTFS is the target Edit: Wou...

Is there a way in windows to know if a process is not responding?

Is there a way to know when a process is hung? is there a win32 call for this? ...