c++

Only compiles as an array of pointers, not array of arrays

Suppose I define two arrays, each of which have 2 elements (for theoretical purposes): char const *arr1[] = { "i", "j" }; char const *arr2[] = { "m", "n" }; Is there a way to define a multidimensional array that contains these two arrays as elements? I was thinking of something like the following, but my compiler displays warnings ab...

STL list - how to find a list element by its object fields

I have a list: list<Unit *> UnitCollection; containing Unit objects, which has an accessor like: bool Unit::isUnit(string uCode) { if(this->unitCode == uCode) return true; else return false; } How do I search my UnitCollection list by uCode and return the corresponding element (preferably and iterator). In ...

Using mem_fun_ref with boost::shared_ptr

Following the advice of this page, I'm trying to get shared_ptr to call IUnknown::Release() instead of delete: IDirectDrawSurface* dds; ... //Allocate dds return shared_ptr<IDirectDrawSurface>(dds, mem_fun_ref(&IUnknown::Release)); error C2784: 'std::const_mem_fun1_ref_t<_Result,_Ty,_Arg> std::mem_fun_ref(Result (_thiscall _Ty::* )...

Quick question about pointers

So, I have this code fragment: int * iPtr ; int * jPtr ; int i = 5, k = 7; iPtr = &i; jPtr = iPtr ; I have just started learning about pointers, and need to get some doubts cleared. is jPtr now essentially also pointing at i? I know I can change the value of i by using *iPtr, but how can I change the value of the object being pointe...

code throws std::bad_alloc, not enough memory or can it be a bug?

I am parsing using a pretty large grammar (1.1 GB, it's data-oriented parsing). The parser I use (bitpar) is said to be optimized for highly ambiguous grammars. I'm getting this error: 1terminate called after throwing an instance of 'std::bad_alloc' what(): St9bad_alloc dotest.sh: line 11: 16686 Aborted bitpar -p -b 1...

Swapping values using pointers

I have this code fragment int i = 5; int k = 7; int * iPtr; int * jPtr; int * kPtr; iPtr = &i; kPtr = &k; I am required to swap i and k using the pointers. This is how I'm doing it: *jPtr = *kPtr ; *kPtr = *iPtr ; *iPtr = *jPtr ; Is this the best way to do it, or is there a better way? ...

how to get time in millis in c++ just like java

In Java you can do this: long now = (new Date()).getTime(); How can I do the same but in c++ ? ...

Performing full screen grab in windows

I am working on an idea that involves getting a full capture of the screen including windows and apps, analyzing it, and then drawing items back onto the screen, as an overlay. I want to learn image processing techniques and I could get lots of data to work with if I can directly access the Windows screen. I could use this to build aut...

Multiple inclusion of header file c++

I have a problem regarding multiple inclusion of header file in C++ code. say for example, i have three class X,Y,Z. X and Y are derived from Base class Z. And i want to create an instance of X in Y. The code will go like this. class Z{some code} class X:public Z{some code};//here #include header of class Z added class Y:public Z //...

C++ map performance - Linux (30 sec) vs Windows (30 mins) !!!

I need to process a list of files. The processing action should not be repeated for the same file. The code I am using for this is - using namespace std; vector<File*> gInputFileList; //Can contain duplicates, File has member sFilename map<string, File*> gProcessedFileList; //Using map to avoid linear search costs void processFile(Fi...

how to call operator () in c++

in c++ i have following code class Foobar{ public: Foobar * operator()(){ return new Foobar; }; My quesion is how to call the (); if i do Foobar foo() the constructor gets called i am confused about behaviour of () can some explain me ...

Member Function Pointer not quite right

I have a SpecialisedRedBlackTree class that is templated. My Month class is not. In my Month class I have a private member which is an instance of SpecialisedRedBlackTree: SpecialisedRedBlackTree<Day> m_windSpeedTree; As you can see it will take the Day class/object (please correct me on any terms I get wrong). In my Month class, I...

What C/C++ code is used to send an HTTP request to a server using editors like gedit(in Ubuntu)

Note: The original was worded in quite a confusing manner. I tried to rewrite it while maintaining the original intent. -George I need to send a request using GET/POST method to a server and check its response. I need some code in C/C++ to check whether my request was successful or not. ...

In game programming are global variables bad?

I know my gut reaction to global variables is "badd!" but in the two game development courses I've taken at my college globals were used extensively, and now in the DirectX 9 game programming tutorial I am using (www.directxtutorial.com) I'm being told globals are okay in game programming ...? The site also recommends using only structs...

zlib gzgets extremely slow?

I'm doing stuff related to parsing huge globs of textfiles, and was testing what input method to use. There is not much of a difference using c++ std::ifstreams vs c FILE, According to the documentation of zlib, it supports uncompressed files, and will read the file without decompression. I'm seeing a difference from 12 seconds using ...

Header files inclusion / Forward declaration

Hi, In my C++ project when I have to go for the inclusion (#include "myclass.h") of header files?? And when I have to go for forward declaration of the class (class CMyClass;) ?? Any suggestions regarding this are welcome. ...

How to Handle SIGSEGV and print back trace on receiving SIGSEGV in c/C++ program?

Hi Guys, I m constructing a C++ program in which I need to handle SIGSEGV and Signal handler should be able to print the Back Trace. Can any one help in this. Regards ...

Class destructor memory handling in C++

What potential memory leaks won't an implicit destructor handle? I know that if you have anything stored on the heap it won't handle it, and if you have a connection to a file or a database, that needs to be handled manually. Is there anything else? What about, say, non-base data types like vectors? Also, in an explicit destructor, need...

What C/C++ library do I use to change an HTTP packet in windows?

It seems winpcap can't be used to do this kind of job(ref), then which library to use alternatively? ...

how to rebuilt a specific dependent library with /MD mode in c++ VS2005 ?

One of my specific dependent library is built with /ML. How to rebuil it with /MD? Thanks in advance! ...