c++

How can we visualizat a binary tree in C++

Hi, When I have implemented binary trees , one of the first utilities one writes is a visualization function that given a tree prints it to the screen. using cout function to print it every time like a stack is probleme to me , I can't represent the value of my job . Printing trees properly in ASCII is quite difficult to understand.Mea...

Area of a irregular shape

I have set of points which lies on the image. These set of points form a irregular closed shape. I need to find the area of this shape. Does any body which is the normal algorithm used for calculating the area ? Or is there any support available in libraries such as boost? I am using C++. ...

Trying to right click on code in VS2008 causes lockup.

Working on a Win32 DLL using Visual Studio 2008 SP1 and, since yesterday, whenever I try to right click on code, to go to a variable definition for example, VS completely locks up and I have to manually kill the process. To make it even weirder, whenever this happens the devenv.exe process uses exactly 25% of the CPU. And I mean exactly...

Help with Boost Grammar

I have been using the following win32 console code to try to parse a B Machine Grammar embedded within C++ using Boost Spirit grammar template. I am a relatively new Boost user. The code compiles, but when I run the .exe file produced by VC++2008, the program partially parses the input file. I believe the problem is with my grammar defin...

Why does the MSCVRT library generate conflicts at link time?

I am building a project in Visual C++ 2008, which is an example MFC-based app for a static C++ class library I will be using in my own project soon. While building the Debug configuration, I get the following: warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library After using the recommende...

How to log when a particular memory location gets written and by which function?

I have a bug which happens very rarely but crashes my C++ program. It's seems I have a buffer overflow problem or something similar. I find that these types of bug are the most difficult to diagnose. My program always crashes because of the same corrupted memory location. Is there some debugging tool which could detect when a particular...

Interview question: Check if one string is a rotation of other string.

A friend of mine was asked the following question today at interview for the position of software developer: Given two string s1 and s2 how will you check if s1 is a rotated version of s2 ? Example: If s1 = "stackoverflow" then the following are some of its rotated versions: "tackoverflows" "ackoverflowst" "overflowstack" where as...

What's the difference between starting a process from the dock vs. the command line on OS X

I'm debugging an issue on OS X that only occurs when the application is started from the dock. It does not happen when the app is started from the command line. What is the difference between the two scenarios? The code I'm working with is a c++ based bundled plug-in being loaded in a third party app. I've attached to the process wit...

Array performance question

I am very familiar with STL vector (and other container) performance guarantees, however I can't seem to find anything concrete about plain arrays. Are pointer arithmetic and [] methods constant or linear time? ...

C++: Conceptual problem in designing an intepreter

I'm programming an interpreter for an experimental programming language (educational, fun,...) So far, everything went well (Tokenizer & Parser), but I'm getting a huge problem with some of the data structures in the part that actually runs the tokenized and parsed code. My programming language basically has only two types, int and stri...

How to check if memory has been initialized?

Is there a way of checking if memory pointed to by pointer has been initialized?(not necessarily by my program). Thanks ...

Sort a list of pointers.

Hello all, Once again I find myself failing at some really simple task in C++. Sometimes I wish I could de-learn all I know from OO in java, since my problems usually start by thinking like Java. Anyways, I have a std::list<BaseObject*> that I want to sort. Let's say that BaseObject is: class BaseObject { protected: int id; public...

how to use WaitForSingleobject

hello in order to try out how to programm with the win32 api i wrote a programm that creates a process. then i want to check if my proccess waits for the new created process, close the handle and then check waitforsingle obj. again. (the seconde process is sleeping for 700 ms) first process: #include <iostream> #include <windows.h> #in...

c++ template and its element type

This is my template matrix class: template<typename T> class Matrix { public: .... Matrix<T> operator / (const T &num); } However, in my Pixel class, I didn't define the Pixel/Pixel operator at all! Why in this case, the compiler still compiles? Pixel class #ifndef MYRGB_H #define MYRGB_H #include <iostream> using namespace std; ...

Learning C++ as a Perl programmer

I'm a Perl5 programmer for 7 years and I'm trying to learn C++ now. Some of the C++ syntax is hard for me to understand and to think in C++ way. For example: In Perl, you can mix the data in the arrays @array = (1,"string",5.355); You can assign any value to a scalar variable: $var = 1; $var = "string"; $var = \$reference_to_scalar;...

Changing the system time zone succeeds once and then no longer changes

I'm using the WinAPI to set the time zone on a Windows XP SP3 box. I'm reading the time zone information from the HKLM\Software\Microsoft\WindowsNT\Time Zones\<time zone name> key and then setting the time zone to the specified time zone. I enumerate the keys under the Time Zones key, grab the TZI value and stuff it into a TIME_ZONE_IN...

Array pointer arithmetic question

Is there a way to figure out where in an array a pointer is? Lets say we have done this: int nNums[10] = {'11','51','23', ... }; // Some random sequence int* pInt = &nNums[4]; // Some index in the sequence. ... pInt++; // Assuming we have lost track of the index by this stage. ... Is there a way to deter...

Inclusion of dshow.h results in definition errors

I am trying to do a few things using DirectShow for audio playback. I have a header file, at the top is: #pragma once #include <dshow.h> #pragma comment(lib, "strmiids.lib") and then it goes on to define a class. When including dshow.h I get the following complilation errors: C:\Program Files\Microsoft SDKs\Windows\v7.0\include\dd...

Can shared memory be read and validated without mutexes?

On Linux I'm using shmget and shmat to setup a shared memory segment that one process will write to and one or more processes will read from. The data that is being shared is a few megabytes in size and when updated is completely rewritten; it's never partially updated. I have my shared memory segment laid out as follows: -------...

Linker error: wants C++ virtual base class destructor

Hi, I have a link error where the linker complains that my concrete class's destructor is calling its abstract superclass destructor, the code of which is missing. This is using GCC 4.2 on Mac OS X from XCode. I saw http://stackoverflow.com/questions/307352/g-undefined-reference-to-typeinfo but it's not quite the same thing. Here is t...