c++

Get pContext in Try/Catch handler?

When an exception happens, as you know, it passes pContext to the SEH. Is there anyways to access the pContext in a Try/Catch? I guess I could have the exception class grab it when being initiated but that would only work for that class and not for every exception. ...

How to find memory leaks in source code

If it is known that an application leaks memory (when executed), what are the various ways to locate such memory leak bugs in the source code of the application. I know of certain parsers/tools (which probably do static analysis of the code) which can be used here but are there any other ways/techniques to do that, specific to the langua...

Difference in behavior when returning a local reference or pointer

#include <iostream.h> using namespace std; class A { public: virtual char* func()=0; }; class B :public A { public: void show() { char * a; a = func(); cout << "The First Character of string is " << *a; } char * func(); }; char* B::func() { cout << "In B" << endl; char x[] = "String"; return x; ...

Need Help for C++ Code Dissection at /*=NULL*/

Could you tell me the meaning of /*=NULL*/ below? CMyCla::CMyCla(CWnd* pParent /*=NULL*/) : CDialog(CCycleTimes::IDD, pParent) { // Some code here } And btw, i copied the same line. Commented successfully as the syte below // CMyCla::CMyCla(CWnd* pParent /*=NULL*/) // : CDialog(CCycleTimes::IDD, pParent) Otherwise, commen...

Most efficient method to parse small, specific arguments

I have a command line application that needs to support arguments of the following brand: all: return everything search: return the first match to search all*search: return everything matching search X*search: return the first X matches to search search#Y: return the Yth match to search Where search can be either a single keywor...

How do compilers know where to find #include <stdio.h>?

I am wondering how compilers on Mac OS X, Windows and Linux know where to find the C header files. Specifically I am wondering how it knows where to find the #include with the <> brackets. #include "/Users/Brock/Desktop/Myfile.h" // absolute reference #include <stdio.h> // system relative reference? I assum...

Using boost::bind output as an array subscript.

How do I get boost::bind to work with array subscripts? Here's what I'm trying to achieve. Please advice. [servenail: C++Progs]$ g++ -v Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr /share/info --enable-shared --enable-threads=posix --di...

serialise nested unordered maps

Dear StackOverFlowers, I've got a variable with a declaration that looks like boost::unordered_map< std::string, boost::unordered_map <long,int>, hashe::fnv_1a> _pl; I need to serialise this to a file and and deserialise later. Should I just do a nested loop or can i do something ultracool with boost::serialisation? Any help pointing...

a C++ hash map that preserves the order of insertion

I have the following code: #include <iostream> #include "boost/unordered_map.hpp" using namespace std; using namespace boost; int main() { typedef unordered_map<int, int> Map; typedef Map::const_iterator It; Map m; m[11] = 0; m[0] = 1; m[21] = 2; for (It it (m.begin()); it!=m.end(); ++it) cout << i...

How do I convert a boost::asio::streambuf into a std::string?

I would like to convert a boost::asio::streambuf into a std::string. How do I do that easily? ...

Default argument in a function [C++]

Hi, I tried to do something like this: int& g(int& number = 0) { //maybe do something with number return number; } but it doesn't work. It has to be passed by reference. Thank you for any help. P.S. I think that "Related Questions" appearing once you type Title is a good idea, but I also think that they should be displayed only i...

Losing whitespace around escaped symbols in CDATA using Expat XML parser in C++

I'm using XML to send project information between applications. One of the pieces of information is the project description. So I have: <ProjectDescription>Test &amp; spaces around&amp;some &amp; amps!</ProjectDescription> Or: "Test & spaces around&some & amps!" <-- GOOD! When I then use Expat to parse it, my data handler gets ju...

What is the appropriate English language terminology for referring to the object in C++?

What is the correct / appropriate English terminology for referring to the "current" object in C++. For example, say you are writing a comment in the body of the implementation of this: Thing Thing::operator+(const Thing& other) You have the variable name "other" to use for the other object, but what word / expression do you use to r...

C++ compiler differences ( VS2008 and g++)

I tried compiling the following code in Linux and VS 2008: #include <iostream> // this line has a ".h" string attached to the iostream string in the linux version of the code using namespace std; // this line is commented in the linux version of the code void main() { int a=100; char arr[a]; arr[0]='a'; cout<<"array is:"<<arr...

How do you convert from a nsACString to a LPCWSTR?

I'm making a firefox extension (nsACString is from mozilla) but LoadLibrary expects a LPCWSTR. I googled a few options but nothing worked. Sort of out of my depth with strings so any references would also be appreciated. ...

Where does the C++ compiler start?

If you have a c++ project with several source files and you hit compile, which file does the compiler start with? I am asking cause I am having some #include-dependency issues on a library. Compiler would be: VC2003. ...

Transitioning from desktop app written in C++ to a web-based app

We have a mature Windows desktop application written in C++. The application's GUI sits on top of a windows DLL that does most of the work for the GUI (it's kind of the engine). It, too, is written in C++. We are considering transitioning the Windows app to be a web-based app for various reasons. What I would like to avoid is having...

Behaviour of std::partition when called on empty container?

I ran into a problem when calling std::partition on an empty container (std::list). std::list<int>::iterator end_it = std::partition(l.begin(), l.end(), SomeFunctor(42)); std::list<int>::iterator it = l.begin(); while (it != end_it) { // do stuff } If the list is empty, std::partition returns an iterator, that is not equal to l.end...

Boost (v1.33.1) Thread Interruption

How can I interrupt a sleeping/blocked boost::thread? I am using Boost v1.33.1, upgrading is not an option. Thank you. ...

How to tunnel TCP over reliable UDP?

Assume I have a reliable UDP library, and want to tunnel arbitrary TCP connections over it. This is my current approach to doing so, but I feel that it may not be very efficient. Any suggestions are very welcome. Client establishes a reliable UDP connection to server. Client runs a local SOCKS5 proxy, which receives data from any app t...