c++

Class layout in C++: Why are members sometimes ordered?

The C++ standard dictates that member variables inside a single access section must be layed out in memory in the same order they were declared in. At the same time, compilers are free to choose the mutual ordering of the access sections themselves. This freedom makes it impossible in theory to link binaries created by different compil...

Can C++ access sections be interleaved?

The C++ standard imposes an ordering on class member variables in memory. It says that the addresses of member variables have to increase in the order of declaration, but only inside one access section. Very specifically, this does not seem to prevent compilers from laying out access sections in an interleaved way. For example: class...

What can cause strange gcc error "mode_t has not been declared" (and others) in system headers?

This is the compiler message (somewhat stripped): /usr/include/sys/mman.h:145: error: 'mode_t' has not been declared Another error: In file included from /usr/include/sys/resource.h:25, from /usr/include/sys/wait.h:32, /usr/include/bits/resource.h:172: error: field 'ru_utime' has incomplete type /usr/include/bits/res...

last key in a std::map

I am looking for the highest key value (a defined by the comparison operator) of a std::map. Is this guaranteed to be map.rbegin()->first ? (I am a bit shaky on reverse iterators, and how much freedom there is in the implementation of std::map) If not, please advise. I cannot change the data structure. ...

Calculating a boundary around several linked rectangles.

Hi,I am working on a project where I need to create a boundary around a group of rectangles. Let's use this picture as an example of what I want to accomplish. EDIT: Couldn't get the image tag to work properly, so here is the full link: http://www.flickr.com/photos/21093416@N04/3029621742/ We have rectangles A and C who are linked by...

Posting to a URL with wxWidgets

Does anyone have some sample code showing how to POST to a URL using wxWidgets? The documentation and discussion forums imply that it's possible but the methods in wxHTTP are very low-level compared to what you find in .NET and scripting languages like Perl and Ruby. Do I actually have to create the HTTP request myself and send it to the...

Boost 1.37

I can't find a pre-built set of MSVC++ libs for Boost 1.37.0 (latest stable version), only the source. I don't understand how their weird build system works... are there any places I can find a download of a visual studio project or something? ...

Initalizing ArcEngine, Make it Faster?

I am currently working on a C++/COM project using ArcEngine(From ESRI). Aside from the fact that there is little to no support in terms of documentation (SDK is there.) Anyways, i am wondering if anyone here has had any experience in making the initialization process of ArcEngine faster. Right now it takes 30-35 seconds just to initializ...

Is there a way to use pre-compiled headers in VC++ without requiring stdafx.h?

I've got a bunch of legacy code that I need to write unit tests for. It uses pre-compiled headers everywhere so almost all .cpp files have a dependecy on stdafx.h which is making it difficult to break dependencies in order to write tests. My first instinct is to remove all these stdafx.h files which, for the most part, contain #include ...

Is the return type part of the function signature?

In C++, is the return type considered part of the function signature? and no overloading is allowed with just return type modified. ...

How to parametrize a test using cppunit

We are using cppunit, i am trying to run the same test using different parameters, running a loop inside the test is not a good option as any failure will abort the test. I have looked at TestDecorator and TestCaller but neither seem to really fit. Code samples would be helpful. Thanks. ...

Event Handler for Minimize and Maximize Window

Hi, I am developing an application for PocketPC. When the application starts the custom function SetScreenOrientation(270) is called which rotates the screen. When the application closes the function SetScreenOrientation(0) is called which restores the screen orientation. This way the screen orientation isn't restored if the user minim...

Macro Replacement during Code Generation

Presently I have a some legacy code, which generates the op code. If the code has more number of macros then the code generation takes so much of time (In terms of hours!!). I have gone through the logic, they are handling the macro by searching for it and doing a replace of each variable in it some thing like inlining. Is there a way th...

Simple text menu in C++

I am writing a silly little app in C++ to test one of my libraries. I would like the app to display a list of commands to the user, allow the user to type a command, and then execute the action associated with that command. Sounds simple enough. In C# I would end up writing a list/map of commands like so: class MenuItem { ...

Does this code remove a file extension?

This isn't my code; I am trying to figure out what exactly this does. This is a part of a big, ancient system written in C (actually it was written 4 years ago, but most likely written by a late 80s programmer mentality). Part of the code: char DestFile[256]; char DestFile2[256]; //This part is just to show an example strcpy(DestFile, ...

How to overload operator<< that doesn't take or return ostream

Original Question I am writting a logging class where the goal is to be able to do this: // thread one Logger() << "Some string" << std::ios::hex << 45; // thread two Logger() << L"Some wide string" << std::endl; Currently my Logger header looks something like this: #pragma once; #include <ostream> class Logger { public: Log...

warning C4244: 'argument' : conversion from 'SIZE_T' to 'DWORD', possible loss of data

I need to have a set of overloaded functions in my code but I get convertion wanrings. Here is a test code: #include windows.h void f(DWORD arg){...} //void f(SIZE_T arg){} void main(void) { DWORD dword=0; SIZE_T size_t=dword; f(size_t); } The compiler gives warning: test.cpp(11) : warning C4244: 'argument' : conversion from 'SIZ...

C++: Derived + Base class implement a single interface?

In C++, is it possible to have a base plus derived class implement a single interface? For example: class Interface { public: virtual void BaseFunction() = 0; virtual void DerivedFunction() = 0; }; class Base { public: virtual void BaseFunction(){} }; class Derived : public Base, public Interface { ...

How to know (in GCC) when given macro/preprocessor symbol gets declared?

Suppose I have #define foo in various header files. It may expand to some different things. I would like to know (when compiling a .cc file) when a #define is encountered, to what it will expand, it which file it is and where it got included from. Is it possible? If not, are there any partial solutions that may help? Feel free to add c...

Saving extra data in a dll, how did they do it?

Hello all, let me tell you a bit about where this question came from. I have been playing around with the SDK of Serious Sam 2, a first person shooter which runs on the Serious Engine 2. This engine introduces something called MetaData. MetaData is used in the engine to serialize classes and be able to edit them in the editor environment...