c++

Help with rake dependency mapping.

I'm writing a Rakefile for a C++ project. I want it to identify #includes automatically, forcing the rebuilding of object files that depend on changed source files. I have a working solution, but I think it can be better. I'm looking for suggestions for: Suggestions for improving my function Libraries, gems, or tools that do the work f...

Unable to instantiate function templates which uses decltype to deduce return type, if called from inside a lambda?

I'm trying to use C++0x, and in particular lambda expression and decltype to simplify some of my code, using the MSVC10 RC compiler. I've run into the following very odd problem: template <typename F> auto foo(F f) -> decltype(f()){ return f(); } template <typename F> void bar(F f){ f(); } int main() { bar([](){ foo([]() { ...

Prevent scientific notation in ostream when using << with double

I need to prevent my double to print in scientific notation in my file, when I do this outfile<<X; ...

Why check if (*argv == NULL)?

In the data structures class that I am currently taking, we have been tasked with writing a web crawler in C++. To give us a head start, the professor provided us with a program to get the source from a given URL and a simple HTML parser to strip the tags out. The main function for this program accepts arguments and so uses argc/argv. Th...

Find pointers from pointee

From this code: int x = 5; int other = 10; vector<int*> v_ptr; v_ptr.push_back(&x); v_ptr.push_back(&other); v_ptr.push_back(&x); Is there anyway I can know who points at x, from the x variable itself, so that I don't have to search inside v_ptr for address of x? Is this possible in C++ or C++0x? I read that when doing garbage col...

What web server interface to choose?

I'm in the process of planning a web service, which will be written in C++. The goal is to be able to select more or less any web server to drive the service. For this to become true, I obviously have to choose a standardized interface between web servers and applications. Well known methods that I've heard of are: CGI FastCGI W...

Are there cases where a class declares virtual methods and the compiler does not need to use a vptr?

I was wondering if there is a possible optimization where the compiler does not need to assign a vptr to an instantiated object even though the object's type is a class with virtual methods. For example consider: #include <iostream> struct FooBase { virtual void bar()=0; }; struct FooDerived : public FooBase { virtual void bar() {...

How to Access/marshall char *variable from dll import in C#

Hi I need to access functionality from win32 dll , for that I am using [dllimport] in C# code. what exact method signature i need to create with [dllimport] for the following c++ methods void GetGeneratedKey(char *code, int len, char *key) pls help in this. Thanks nRk ...

Adding Boost Library to a C++ project in Windows Eclipse

I recently installed the Boost Library on Windows using the installer, I'm trying to link to the library in Eclipse but am not having any luck. I tried going through Project Properties -> C/C++ Build -> Settings -> MinGW C++ Linker -> Libraries and add the reference "boost_filesystem" according to this website: http://www.ferdychristant...

Difference between const. pointer and reference?

Hi What is the difference between a constant pointer and a reference? Constant pointer as the name implies can not be bound again. Same is the case with the reference. I wonder in what sort of scenarios would one be preferred over the other. How different is their C++ standard and their implementations? cheers ...

How do I know which thread called a method

I have a threadSafe method that gets called by multiple threads. Is there a way to know which thread called it? ...

Using Boost Graph Library on Mac Eclipse

I have a similar question regarding using Boost under Windows. I'm very new to Boost and I just installed the Boost library on my Mac, I'm interested primarily in the Boost Graph Library. My questions are as follows, when installing Boost by default on my Mac, is the BGL installed automatically as well? I ask this because the Boost web...

what happens when tried to free memory allocated by heap manager, which allocates more than asked for?

This question was asked to me in an interview. Suppose char *p=malloc(n) assigns more than n,say N bytes of memory are allocated and free(p) is used to free the memory allocated to p. can heap manager perform such faulty allocation ? what happens now, will n bytes are freed or N bytes are freed? is there any method to find how much m...

error C2228: left of '.DXGI_MODE' must have class/struct/union Direct X

I am trying to setup my swap chain Buffer but I get the following error error C2228: left of '.DXGI_MODE' must have class/struct/union 1> type is 'DXGI_MODE_SCANLINE_ORDER' Note sure what I am doing wrong. here is the code DXGI_SWAP_CHAIN_DESC swapChainDesc; // Set the width and height of the buffers in the swap chain ...

what is the use of member template functions in c++?

a class having member template function like this template <typename t> class complex { public: complex(t r, t im); template<typename u> complex(const complex<u>&); private: //what would be the type of real and imaginary data members here. } i am confused about member template function, please provide an example by whi...

What is faster : Java or C++ ?

What language is faster? Java or C++? On web, I have come across a multitude of benchmarks who claim one is faster than the other. And yes, I would also like to know whether these differences do have any significance in application development or not? I am really confused. Please shed some light on this. Thanks. ...

Google Codejam 2009 Qualification problem: Watershed in C++

I tried out this Codejam problem and produced a valid solution in C++. There is a Python solution on the website. Was wondering if any C++ people would offer some improvements/optimizations to this solution. Thanks! BTW: In Codejam the goal is to write code as fast as possible (a reason why Python would have been a better language choic...

Preprocessor syntax to use an #define as an identifier (function name) and a string

I'm not sure if this is possible, but I would like to create a shared object file and I would like to make it easy to use by having a #define that can be used to dereference the function names. In libfoo.h #define FOO_SO_FUNCTION_A aFunction In libfoo.so #include "libfoo/libfoo.h" extern "C" int FOO_SO_FUNCTION_A( void ) { ....

Using make for my program

I have a bunch of files in different folders: /ai/client.cpp # contains the main function /ai/utils/geometry.h /ai/utils/geometry.cpp /ai/world/world.h /ai/world/world.cpp /ai/world/ball.h /ai/world/ball.cpp /ai/world/bat.h /ai/world/bat.cpp How do I write a makefile to compile this program? I'm using Ubuntu. ...

Can marshalling or packing be implemented by unions?

In beej's guide to networking there is a section of marshalling or packing data for Serialization where he describes various functions for packing and unpacking data (int,float,double ..etc). It is easier to use union(similar can be defined for float and double) as defined below and transmit integer.pack as packed version of integer.i, ...