c++

Boost::any and polymorphism.

I am using boost::any to store pointers and was wondering if there was a way to extract a polymorphic data type. Here is a simple example of what ideally I'd like to do, but currently doesn't work. struct A {}; struct B : A {}; int main() { boost::any a; a = new B(); boost::any_cast< A* >(a); } This fails because a is ...

Keeping C# and C++ classes in sync at runtime?

Hi, My application is built in two sections. A C# executable which is the front end UI and a C++ dll which is more the low-level stuff. My application creates and manages many instances of objects, where every C++ object instance has a corresponding C# object instance. What techniques or libraries can I use to ensure that objects in the...

How correctly organize shared class members?

Suppose I have a function y of n variables x[0]..x[n-1]: y = 1 + a[0][0]*x[0] + a[1][0]*x[0]^2 + a[0][1]*x[1] + a[1][1]*x[1]^2 + ... I want to find values of variables x[0]..x[n-1], which minimize y. This optimization task will be performed by a genetic algorithm. The basic steps of the algorithm are: Generate a pool (population) of...

is size_t always unsigned?

As title: is size_t always unsigned, i.e. for size_t x, is x always >= 0 ? ...

C++ STL Range Container

I'm looking for a container that maps from a double to object pointers. However, each key is simply a range of doubles that would correspond to that object. For example, there could be a key/value pair that's <(0.0 3.0), ptr>, or <(3.5 10.0), ptr2> container[1.0] should return ptr, container[3.0] should also return ptr, and container[-...

Memory leak in Mixed Mode C++/CLR application

I'm having problems with a slow memory leak in my mixed mode C++/CLR .NET application. (It's C++ native static libraries linked into a VS2008 C++/CLR Windows Forms app with the "/clr" compiler setting) Typical behaviour: app starts using 30 MB (private memory). Then leaks memory slowish, say a MB every hour when running under simulated...

Learning C++ from scratch in Visual Studio?

I need to get up to speed with C++ quite quickly (I've never used it previously) - is learning through Visual Studio (i.e. Managed C++) going to be any use? Or will I end up learning the extensions and idiosyncracies of C++ in VS, rather then the language itself? If learning in VS is not recommended, what platform / IDE do you guys sugg...

When is a forward declaration required?

I have this C++ project that I'm working on All classes have their implementation separated from the .h file. However, I'm not certain why/when forward declarations are required. For example, I just ran into an error when I #included "ClassType.h", the compiler completely refuses to compile a class that had a pointer to ClassType, eve...

Eclipse CDT: How to reference 3rd party includes via a Relative path

I'm new to Eclipse-CDT, setting up a new project for the first time. I'm trying to reference Boost without hardcoding an absolute path. I've put boost in my workspace folder, e.g. /home/user/workspace/boost_1_39_0 I was then hoping to add an include directory pointing to that folder relative to the workspace, but Eclipse won't do that,...

Compiler errors from simple Visual C++ project

Hello I'm trying to make program run. When I try Hello World in win32 project/.cpp file I get bunch of errors 1>------ Build started: Project: HelloWorld3, Configuration: Debug Win32 ------ 1>Compiling... 1>hello.cpp 1>...\projects\helloworld3\helloworld3\hello.cpp(7) : error C2065: 'cout' : undeclared identifier 1>...\projects\hellowo...

Designing a class architecture for network messages

I have client/server applications and a very simple protocol for communication. More precisely, it's a set of commands a server sends and a set of requests a client can make. The idea is as follows: When a command is made by the server, a client has to execute it. When a request is made, server checks permissions and if everything is o...

Referencing 3rd party Libraries using *relative* paths in Eclipse-CDT

Hi, what is the best practice to reference 3rd party C++ components (e.g. includes, libraries) using relative paths in Eclipse-CDT? I'm trying to reference Boost and Google protobuf. I've put them each in a folder in my workspace, e.g. /home/user/workspace/boost_1_39_9 I've added a reference to that folder under build settings in the p...

Same Header File for both DLL and Static Library.

So the common (at least VS 2005 states) way to define exports/imports for a DLL is: #ifdef MY_EXPORTS #define MY_API __declspec(dllexport) #else #define MY_API __declspec(dllimport) #endif class MY_API MyClass { ... }; This works great if I'm just building my code as a DLL. However, I want to have the option of using a static lib...

How can I access the points of the polygon stored in Postgres using Libpqxx?

I want to retrieve the points of a polygon that are stored in the postgres db. The contents of the db are: polygonid |vertices -----------+--------------------------------------------------------------------- 2 |((1,0),(1.5,-1),(2,-1),(2,1),(1,1),(0,0),(0,2),(3,2),(3,-2),(1,-2)) 4 | ((3,3),(4,4),(5,5)) The vertices ...

How do you farm out variables to persistent data?

Basically, I want to have my program retrieve various variables from the hard drive disk for use in the program. I guess, before asking for details, I should verify that is even possible. Is it? If it is, what is the best way? I've seen the use of .ini files, but I don't know how to retrieve data specifically from .ini files. Is it the ...

Convert PHP to C++ code

I'm looking for a way to convert PHP code to C++. There are a few reasons I want to do so: Main reason: There are bunch of great PHP tools/software that I'd love to use and incorporate into C++ GUI or non-GUI applications To boost performance To avoid dependency on PHP libraries To avoid disclosing source code on shared hosting enviro...

Get the graphics card model?

hi all, I was wondering how I can get the graphics card model/brand from code particularly from DirectX 9.0c (from within C++ code). Thanks for any help! ...

Parameters to watch while running an application on linux?

Hello, I am running an application overnight on my Linux xscale device. I am looking for things,which would increase with the increase in the amount of time of running. One thing,is the memory. If you observe the memory on the xscale systems,the free memory would start decreasing,but you will see an increase in the cached memory. What ar...

How to output array of doubles to hard drive?

I would like to know how to output an array of doubles to the hard drive. edit: for further clarification. I would like to output it to a file on the hard drive (I/O functions). Preferably in a file format that can be quickly translated back into an array of doubles in another program. It would also be nice if it was stored in a stan...

gSOAP for WCF server with TCP binding and Callback events

Hi, We need a C++ client application to consume WCF server with NetTCPBinding, and Callback events supported. I have generated the proxy using gSOAP 2.7.10. But my proxy does not communicate with server. When I use BasicHttp binding, it seems to work. Not sure of events. Can anyone suggest me, if gSOAP works with TCP binding, and callb...