c++

Attaching Member function of a class in pthread

pthread_t thread1; pthread_create(&thread1,NULL,.......,NULL); // Here I want to attach a thread to a member function of class How can I pass the member function of a class in the above code. ...

If-else-if versus map

Hi, Suppose I have such an if/else-if chain: if( x.GetId() == 1 ) { } else if( x.GetId() == 2 ) { } // ... 50 more else if statements What I wonder is, if I keep a map, will it be any better in terms of performance? (assuming keys are integers) ...

How might I assume a "default value" when parsing using boost::spirit?

Let's say I have a grammar defined to something like: some_rule := a b [c [d]] where c, and d are optional and default to a certain value (let's say 14) if not given. Can I get it to default to the 14 if the value isn't given? I want the produced std::vector to always be of size 4. The closest I've come is like the following: qi::ru...

Hash Table v/s STL map in C++

Hi, I am trying to learn C++ maps. Was just wondering about the implementation of STL map. I read it employs Binary search tree. Is there a implementation of hash table in STL? How exactly do STL map stores Key Value pairs? ...

Tutorials for an experienced C# user to learn C++

Are there any good resources for learning C++ that a C# user could use, which don't require knowledge of C? I have quite a good knowledge of C# via courses in my University's game development program (in a 300 level course right now) but now I need to use C++ for a project. I would use a beginner tutorial but they are so hard for me ...

How to partition bits in a bit array with less than linear time

This is an interview question I faced recently. Given an array of 1 and 0, find a way to partition the bits in place so that 0's are grouped together, and 1's are grouped together. It does not matter whether 1's are ahead of 0's or 0's are ahead of 1's. An example input is 101010101, and output is either 111110000 or 000011111. Solv...

Generating tuples from tuples

Say you have a tuple and want to generate a new tuple by applying a metafunction on each type of the first one. What' the most efficient C++ metafuntion to accomplish to this task? Is it also possible to use C++0x variadic template to provide a better implementation? ...

Deriving streambuf or basic_ostringstream?

Hi, I want to derive a stringstream so that I can use the operator<< to construct a message which will then be thrown. The API would look like: error("some text") << " more text " << 42 << std::endl; This should do a throw "some text more text 42" So what I did is make an errorbuf (inheriting from streambuf) which overloads the 'ov...

Cannot convert CString to BYTE array

I need to convert CString to BYTE array. I don't know why, but everything that I found in internet does not work :( For example, I have CString str = _T("string"); I've been trying so 1) BYTE *pbBuffer = (BYTE*)(LPCTSTR)str; 2) BYTE *pbBuffer = new BYTE[str.GetLength()+1]; memcpy(pbBuffer, (VOID*)(LPCTSTR)StrRegID, str.GetLength(...

Template with constant expression: error C2975 with VC++2008

Hello, I am trying to use elements of meta programming, but hit the wall with the first trial. I would like to have a comparator structure which can be used as following: intersect_by<ID>(L1.data, L2.data, "By ID: "); intersect_by<IDf>(L1.data, L2.data, "By IDf: "); Where: struct ID{};// Tag used for original IDs struct IDf{};/...

Window interface instead of console in c.

I have console application in c. I want to convert into window application, kindly guide me so that I can make it possible. ...

Is there any simple way to determine when the popup menu was dismissed?

I'm displaying a popup menu using TrackPopupMenu and would like to know when it is dismissed via clicking outside of it. I've looked through all the menu functions but didn't find anything useful in this regard. Spy++ told me that no window message is sent in this case. So, is there an easy way to do it without installing a mouse hook? ...

Are the following two statements semantically same?

Are the following two statements semantically same? #1 person p("Rahul", 20); #2 person const &p = person("Rahul", 20); EDIT: Sorry, I meant to ask whether the following two are semantically same: #1 person const p("Rahul", 20); #2 person const &p = person("Rahul", 20); ...

which is preferd use istrstream or strtol/strtod for reading number from string.

Hi I have to read number from string .which one is safe and preferred istrstream atoi/atof strtol/strto Please guide me. ...

Are L'A' and 'A' totally same?

When we write a program which supports both unicode and multibytes, we often use _T("some string") macro for strings. But, does a character also need to wrap this macro? Are L'A' and 'A' totally same? Don't we need to wrap _T('A') for a character? ...

Why this works (Templates, SFINAE). C++

Hi guys, referring to yesterday's post, this woke me up this morning. Why does this actually work? As long as the function test is concerned, this function has no body so how can it perform anything? I want to know why and how this works? I'm REALLY interested to see your answers. template<typename T> class IsClassT { private: ...

Writing a Makefile.am to invoke googletest unit tests

I am trying to add my first unit test to an existing Open Source project. Specifically, I added a new class, called audio_manager: src/audio/audio_manager.h src/audio/audio_manager.cc I created a src/test directory structure that mirrors the structure of the implementation files, and wrote my googletest unit tests: src/test/audio/aud...

Debugging instance of another thread altering my data

I have a huge global array of structures. Some regions of the array are tied to individual threads and those threads can modify their regions of the array without having to use critical sections. But there is one special region of the array which all threads may have access to. The code that accesses these parts of the array needs to car...

Problem compiling c++ in CodeGear

I have written a C++ program for a University assignment. I used Netbeans 6.8 running on my Mac and the code runs smoothly, no warnings, errors or problems/bugs. However when compiling and running on a Windows computer using CodeGear RAD Studio 2009 (C++ Builder) am getting several errors. [BCC32 Error] main.cpp(51): E2094 'operator<<' ...

How do I check mysql user have privileges like root user

I use mysql c++ wrapper in client side to connect to mysql server. When user establishes connection to mysql server I want to know whether the user have privileges like root (i.e. GRANT ALL PRIVILEGES ON . TO 'username'@'%' WITH GRANT OPTION).The 'SHOW GRANTS FOR CURRENT_USER' query gives grants for current user, but i need to parse the ...