c++

Can memory be leaked when using vector of pointer in c++?

I tried this: .... vector<players*> player; for (int i = 0; i<10; i++) { player.push_back(new players()); } ... And I wonder if I need to free memory for the vector? If so, how? ...

what is the underlying data structure of a set c++?

I would like to know how a set is implemented in C++. If I were to implement my own set container without using the STL provided container, what would be the best way to go about this task? I understand STL sets are based on the abstract data structure of a binary search tree. So what is the underlying data structure? An array? Also, h...

C++ infix to postfix conversion for logical conditions

I want to evaluate one expression in C++. To evaluate it, I want the expression to be converted to prefix format. Here is an example wstring expression = "Feature1 And Feature2"; Here are possible ways. expression = "Feature1 And (Feature2 Or Feature3)"; expression = "Not Feature1 Or Feature3"; Here And, Or, Not are reserved w...

integrating two systems through email

I want to integrate our bug tracker system and our Support system through emails. The bug tracker can kick out an email on every change to bugs/features. I want to download those emails, parse them and create a formatted email that the Support system can understand (ie the subject could be "Issue #4128 fixed"). What is the simplest ...

a class function with if(this==NULL) test got compiled?

I saw this code snippet during our lab and it actually compiles in MSVC2008 and G++. void LinkList< class T >::Insert(T n) { if (this == NULL) // some code here } As far as I know the this must not be null since you cannot call a class functions in c++ if it wasn't instantiated. Is this a valid code? if so what's the ...

C question: no warning ???

main() { printf("Hello World."); } Why does no warning is produced in gcc compiler even though we declare main() with return type 'int' ...

display multiple errors via bool flag c++

Been a long night, but stuck on this and now am getting "segmentation fault" in my compiler.. Basically I'm trying to display all the errors (the cout) needed. If there is more than one error, I am to display all of them. bool validMove(const Square board[BOARD_SIZE][BOARD_SIZE], int x, int y, int value) { int index...

BITMAPFILEHEADER equivalent in c/c++?

What is the equavalent of the code below in c/C++? ref BITMAPFILEHEADER bmfh = ref buffer[offset]; //Where buffer is a byte[] array ...

regarding C++ stl container swap function

I recently learned that all stl containers have swap function: i.e. c1.swap(c2); will lead to object underlying c1 being assigned to c2 and vice versa. I asked my professor if same is true in case of c1 and c2 being references. he said same mechanism is followed. I wonder how it happens since c++ references cannot be reseted. ...

exchanging 2 memory positions

I am working with OpenCV and Qt, Opencv use BGR while Qt uses RGB , so I have to swap those 2 bytes for very big images. There is a better way of doing the following? I can not think of anything faster but looks so simple and lame... int width = iplImage->width; int height = iplImage->height; uchar *iplImagePtr = (uchar *) iplIm...

C++ MIDI file reading library

I'm trying to write some software to read a MIDI file into an internal data format and use it to control 3D simulated instruments. My biggest problem is reading the MIDI data in from a file, and I'd like to avoid writing all the import code. Does anyone know of a free (preferably Open Source), cross-platform MIDI file reading library? W...

C++ error message output format

If I want to trigger an error in my interpreter I call this function: Error( ErrorType type, ErrorSeverity severity, const char* msg, int line ); However, with that I can only output Name error: Undefined variable in line 1 instead of Name error: Undefined variable 'someVariableName' in line 1 I'm working entirely with strings (...

is there a way to condense a vector (C++)?

I have a sparsely populated vector that I populated via hashing, so elements are scattered randomly in the vector. Now what I want to do is iterate over every element in that vector. What I had in mind was essentially condensing the vector to fit the number of elements present, removing any empty spaces. Is there a way I can do this? ...

Problems with making a simple Unix shell

I am trying to create a simple shell in Unix. I read a lot and found that everybody uses the strtok function a lot. But I want to do it without any special functions. So I wrote the code but I can't seem to get it to work. What am I doing wrong here? void process(char**); int arg_count; char **splitcommand(char* input) { char temp[8...

BOOST.IOstreams: trouble to write to bzip2.

Hello I am would like to store my data in to bzip2 file using Boost.IOstreams. void test_bzip() { namespace BI = boost::iostreams; { string fname="test.bz2"; { BI::filtering_stream<BI::bidirectional> my_filter; my_filter.push(BI::combine(BI::bzip2_decompressor(), BI::bzip2_compressor())) ; my_filter.push(std::fstream(fna...

Help with boost::lambda expression

I tried to write a function that calculates a hamming distance between two codewords using the boost lambda library. I have the following code: #include <iostream> #include <numeric> #include <boost/function.hpp> #include <boost/lambda/lambda.hpp> #include <boost/lambda/if.hpp> #include <boost/bind.hpp> #include <boost/array.hpp> templ...

Using Qt signals/slots instead of a worker thread

I am using Qt and wish to write a class that will perform some network-type operations, similar to FTP/HTTP. The class needs to connect to lots of machines, one after the other but I need the applications UI to stay (relatively) responsive during this process, so the user can cancel the operation, exit the application, etc. My first th...

Reading input from a text file, omits the first and adds a nonsense value to the end?

Hi there When I input locations from a txt file I am getting a peculiar error where it seems to miss off the first entry, yet add a garbage entry to the end of the link list (it is designed to take the name, latitude and longitude for each location you will notice). I imagine this to be an issue with where it starts collecting the input...

SHLoadImageFile(L"\\Program Files\\TrainingApp\\background.png"); whats that L in the argument for?

Hi, ive been working on c++ on linux for the past 2 years,and switched to windows c++ programming recently. can anyone tell me what that L is there in the argument of the function: SHLoadImageFile(L"\\Program Files\\TrainingApp\\background.png"); and on viewing certain sample code in MSVS C++ i came across hundereds of typedefs like...

How to use Ptrace on Linux to print Call Stack of Other Processes of C++.

Hi, i am working on an application which needs call stack of all executing processes on Linux. i am trying to use ptrace but not able to go ahead with it because the steps i need to follow in my code are not clear to me. i also tryied backtrace, but its use is limmited to current process. could some one guide me on the same. Thanks,...