c++

Variadic functions and arguments assignment in C/C++

I was wondering if in C/C++ language it is possible to pass arguments to function in key-value form. For example in python you can do: def some_function(arg0 = "default_value", arg1): # (...) value1 = "passed_value" some_function(arg1 = value1) So the alternative code in C could look like this: void some_function(char *arg0 = "d...

How to align C++ class member names in one column in emacs ?

I would like to align all C++ class member names ( do not confuse with member types ) in one column. Lets look at the example of what we have at entrance: class Foo { public: void method1( ); int method2( ); const Bar * method3( ) const; protected: float m_member; }; and this is what we...

STL Rope - when and where to use

I was wondering under what circumstances you would use a rope over another STL container? ...

what is the reason i am getting out put is 111?

Hi, #include "stdafx.h" #include<iostream.h> template<class T> class Sample { public: Sample(); static int i; }; template<class T> int Sample<T>::i = 0; template<class T> Sample<T>::Sample() { i++; cout<<i; } void main() { Sample<int>s1; Sample<float>s2; Sample<char>s3; } output: 111 what ...

Correct use of boost lambda

Consider the following piece of C++0x code: a_signal.connect([](int i) { if(boost::any_cast<std::string>(_buffer[i]) == "foo") { base_class<>* an_object = new derived_class(); an_object->a_method(_buffer[i]); }}); How would it correctly look in Boost Lambda (since this C++0x feature can't be used in GCC 4.4 yet)? ...

Compile-time (preprocessor) hashing of string

Is there any way to create a hash of string at compile time using the C/C++ preprocessor (or even template-metaprogramming)? e.g. UNIQUE_SALT("HelloWord", 3DES); The idea is that HelloWorld will not be present in the compiled binary, just a hash. Edit: There are many of these declarations spread over a large codebase. ...

empty base class optimization

Two quotes from the C++ standard, §1.8: An object is a region of storage. Base class subobjects may have zero size. I don't think a region of storage can be of size zero. That would mean that some base class subobjects aren't actually objects. Opinions? ...

Unknown Exception on trying to initialize the web service stub created by Axis C++

Hi, I am trying out the sample calculator program given in the folder of axis c++. I am mainly interested in the client side. So I used the wsdl to create the stubs and my main is pretty much the same as given in the sample. However on executing the call Calculator ws (endpoint) I get an unknown exception "First-chance exception at 0...

How to calculate a operation's time in micro second precision

I want to calculate performance of a function in micro second precision on Windows platform. Now Windows itself has milisecond granuality, so how can I achieve this. I tried following sample, but not getting correct results. LARGE_INTEGER ticksPerSecond = {0}; LARGE_INTEGER tick_1 = {0}; LARGE_INTEGER tick_2 = {0}; double uSec = 10000...

VC++ / C++ High performance Multithreaded GUI considerations for trading

I'm interested in seeing what considerations experienced developers make when developing high performance multithreaded GUI's for a windows platform. I ask this question in the context of developing trading applications where GUI's are very dynamic and application latency is an issue. What architectures have you seen or would you recom...

C code compiled with C++: undefined reference

I have a small program that I can compile with GCC and ICC without any difficulties, but I would also like the code to work with G++ and ICPC. I tried to add this: #ifdef __cplusplus extern "C" { #endif at the beginning and this: #ifdef __cplusplus } #endif at the end of all the header files, but I still get several `undefined ...

Is Google Mock a good mocking framework ?

I am pioneering unit testing efforts at my company, and need need to choose a mocking framework to use. I have never used a mocking framework before. We have already chosen Google Test, so using Google Mock would be nice. However, my initial impressions after looking at Google Mock's tutorial are: The need for re-declaring each method ...

How to reduce compile time with C++ templates

I'm in the process of changing part of my C++ app from using an older C type array to a templated C++ container class. See this question for details. While the solution is working very well, each minor change I make to the templated code causes a very large amount of recompilation to take place, and hence drastically slows build time. ...

How to implement tail calls in a custom VM

How can I implement tail calls in a custom virtual machine? I know that I need to pop off the original function's local stack, then it's arguments, then push on the new arguments. But, if I pop off the function's local stack, how am I supposed to push on the new arguments? They've just been popped off the stack. ...

Is there an equivalent of Mac OS X "open" command that can be called from C++/Objective-C code?

On Mac OS X there is a very useful "open" command which launches an application suitable for opened file type. Is there some C++/Objective-C function on Mac which does the same? Note: I know I could launch an "open" process. I'm just not sure if it's the best option. ...

Creating a new window that stays on top even when in full screen mode (Qt on Linux)

I'm using Qt 4.6.3, and ubuntu linux on an embedded target. I call dlg->setWindowState(Qt::WindowFullScreen); on my windows in my application (so I don't loose any real-estate on the touch screen to task bar and status panel on the top and bottom of the screen. This all works fine and as expected. The issue comes in when I want to pop...

Any C++ library for Johansen co-integration test ?

Any Ideas ? Will be highly appreciated. ...

error C2440: '=' : cannot convert from 'const char [2]' to 'char'

I am learning c++, and I am having issues doing some newbie things. I am trying to create a very small application that takes the users input and stores it into a char array. I then parse through that array and remove all parenthesis and dases and display it. like the following (325)858-7455 to 3258587455 But I am getting errors err...

How can i convert from wostream to ostream

i am using a function that receives ostream but i have wostream is there a way to convert one to the other? in particular i want to use boost::write_graphviz which takes ostream but i currently in << operator for wostream. ...

Dizzy-like game level representation (format)

How would you store game level for a Dizzy-like adventure game? How would you specify walkable areas and graphics? Is it tile-based, pixel-based or walkable surfaces can be described by vectors? ...