c++

virtual keyword internals

I heard lots of times virtual function is usually implemented using a vtable. But I actually don't know actually how its implemented and how it works. edit I didn't actually get this code: How can it be rewritten. Can someone explain this in detail please. Finally, let's see how the compiler implements a call to a virtual function. Yo...

Hierarchical data in C++

How can I handle data in C++ like in newer dynamic languages, for example the arrays in PHP are quite neat: $arr = array( "somedata" => "Hello, yo, me being a simple string", "somearray" => array(6 => 5, 13 => 9, "a" => 42), "simple_data_again" => 198792, ); I am open to all suggestions. ...

generate strings with all permutation of character

i have following code #include <iostream> #include <string> using namespace std; string generate(){ for (char c1='A';c1<='Z';c1++){ for (char c2='A';c2 <='Z';c2++){ for (char c3='A';c3<='Z';c3++){ for (char c4='A';c4<='Z';c4++){ return (new string *)(c1) + (ne...

How are attributes parsed in Boost.PropertyTree?

Say I have this XML format: <Widget type="SomeWidget" name="foo"> <Event name="onmouseover"> dostuff(); </Event> </Widget> How do I read the attributes using Boost.PropertyTree? ...

Design pattern for large decision tree based AI in c++

I'm currently writing an AI for a game that is written in c++. The AI is conceptually fairly simple, it just runs through a decision tree and picks appropriate actions. I was previously using prolog for the decision engine but due to the other developers using c++ and some issues with integrating the prolog code I'm now trying to port it...

Difference when omitting the C++ template argument list

When can you omit the C++ template argument list? For example in Visual Studio 2010 this piece of code compiles fine: template<class T> Vec2<T> Vec2<T>::operator+ (const Vec2 &v) const { return Vec2(x + v.x, y + v.y); } If you inline the code, it actually compiles without any argument list. But is this really the same as the follo...

How to convert double to REFERENCE_TIME in c++?

typedef LONGLONG REFERENCE_TIME; I want to convert double Time to REFERENCE_TIME Time, how to do it? ...

Is "for each" Microsoft specific?

Visual C++ 2010 accepts: std::vector<int> v; v.push_back(1); v.push_back(2); v.push_back(3); for each (auto i in v) std::cout << i << std::endl; Is this a C++0x feature or a Microsoft extension? According to Wikipedia, the syntax of C++0x's for-each loop different: int myint[] = {1,2,3,4,5}; for (int& i: myint) { std::cout <<...

Flyweight pattern and C++ templates

I have flyweight pattern. I have abstract class Glyph. I have class Letter and abstract Code derived from Glyph. I have YusciiCode, UniCyrCode and UniLatCode derived from Code. My flyweight factory can be done like this: template <class T> class CodeFactory : public AbstractCodeFactory { public: CodeFactory(); virtual ~Code...

C++: How do I write a function that accepts an iterator and inserts elements?

template<class Container> void BlitSurface::ExtractFrames(Container & output, int frame_width, int frame_height, int frames_per_row, int frames_per_column, bool padding) const { SDL_Surface ** temp_surf = SDL_Ex_ExtractFrames(_surface, frame_width, fram...

How to find programmatically out S/N ratio of a network?

Hi, I have a MANET and am writing an application which will be running on the base station and plugged into the TCP network. I wanted to know how can I figure out the signal-to-noise ratio of a selected node in the MANET? The GUI is based on Qt and I am also using BOOST which I don't have much experience with. I don't know where to st...

Should re-include stuff thats already in the project scope precompiled header?

Not sure if this is a duplicate, please link to similar question if it is. I have a precompiled header stdafx.h which is used in all source files in my project. Thus all headers in the stdafx.h are available in all code files in the project. What I'm unsure about is whether or not to re-include stuff thats alrdy in the precompiled head...

Very large array on the heap (Visual C++)

Hello, I hope some one can help me, i'm trying to create an int[400000000] (400 millions) array on my application using visual c++ 2010 but it generates an overflow error The same code runs on linux with g++. I need this because i'm working with large matrices. Thank you in advance. ...

selecting an appropriate IDE

Which one of the following IDEs/language will you recommend for developing a project under windows that involves recognizing hand gestures and interacting with the OS? I will be using OpenCV library for image processing tasks. After that I will be using win32 APIs or .NET framework to interact with the OS, depending on the tool you sugge...

gdb: Meaning of tstart error "You can't do that when your target is `exec'"

I would like to record the value of a local variable, t, each time that the program reaches a certain line. Accordingly, I tried: (gdb) trace stoer_wagner_min_cut.hpp :197 Tracepoint 1 at 0x4123a0: file ./boost/graph/stoer_wagner_min_cut.hpp, line 197. (gdb) actions Enter actions for tracepoint 1, one per line. End with a line saying j...

Compiler error when using integer as template parameter

What is wrong with the following piece of code? template<typename X> struct A { template<int N> int foo() const { return N; } }; template<typename X> struct B { int bar(const A<X>& v) { return v.foo<13>(); } }; #include <iostream> using std::cout; using std::endl;...

No additional dependencies required for a LIB but are required for a DLL

I have a framework (in C++) which is dependent on a few third party libraries. When I compile a static version of the library framework, no additional dependencies are needed, that is, the lib files of the third part libraries are not needed. When I compile the same framework as a DLL, additional dependencies are now needed otherwise I g...

Iterator loop in C++

I've been googling for this for so long but I couldn't get the answer. The most of sample that I found are based on iterating with vector, map and etc.. I have the code below. multimap<int, int>::iterator it = myMuliMap.find(1); Let's say I have three pairs that has key "1". I like to get those three pair from for loop.. I think t...

a program to monitor a directory on Linux

There is a directory where a buddy adds new builds of a product. The listing looks like this $ ls path-to-dir/ 01 02 03 04 $ where the numbers listed are not files but names of directories containing the builds. I have to manually go and check every time whether there is a new build or not. I am looking for a way to automate this, s...

Why uninitialized global variable is weak symbol?

It seems uninitialized global variable is treated as weak symbol in Gcc. What is the reason behind this? ...