c++

Reopen connected datagram socket

I have a connection protocol that has been defined by our customer. Data are sent between two linux computers using UDP and TCP protocols. The IP addresses and ports are fixed on startup. We are sending messages at 200 Hz and I have been using connect to save some time on the transmissions. My problem is that if there is a communicatio...

call to C and c++ both in a single java program

hi all is it possible to declare to native methods in java so that one method is defined in c and other method is defined in c++.m getting confusion in it . please help me in this. ...

STL Map Value Constructors

I have a class X that I would like to put into an STL map of type std::map. An STL map needs to have X stored in memory somewhere so I'm looking for an efficient (run time and memory) way to create X and store it in the map. I noticed that the following code where x is an object of type X and stlMap is a map of type std::map: stlMap[...

Is this use of nested vector/multimap/map okay?

I am looking for the perfect data structure for the following scenario: I have an index i, and for each one I need to support the following operation 1: Quickly look up its Foo objects (see below), each of which is associated with a double value. So I did this: struct Foo { int a, b, c; }; typedef std::map<Foo, double> VecElem; std...

C++: mixture between vector and list: something like std::rope?

Hi, When storing a bunch of items and I don't need random access to the container, I am using an std::list which is mostly fine. However, sometimes (esp. when I just push back entries to the back and never delete somewhere in the middle), I wish I had some structure with better performance for adding entries. std::vector is bad because...

Clickable menu item with submenu in Qt

Hello, I am writing in Qt 4.6. I am wondering if it's possible to achieve such a menu item, that it's possible to be triggered, but also has a submenu. Clicking it triggers associated action, hovering it causes submenu to appear. ...

What is an efficient way of back-tracking in greedy best search algorithm?

I coded a greedy search algorithm , but it goes to an infinite loop as its not able to back - track , and reach the final state . How can a back-tracking be done in C++ in the most optimal way ! while(!f1.eof() ) { f1>>temp1>>time; A[i].loc_name=temp1; A[i].time_taken=time; ...

Struct containing std::string being passed to lua

I have working C++ code using swig which creates a struct, passes it to lua (essentially by reference), and allows manipulation of the struct such that the changes made in the lua code remain once I've returned to the C++ function. This all works fine until I add a std::string to the struct, as shown here: struct stuff { int x; ...

Searching by extensions in specific Dir C++

In specific directory i need to find all files with some specific extension (for example .log) and than save it somewhere. In need only c++ solutions cause i'm trying it on win 2003 server and c++ is my restrictions. Thank you very munch ...

Learning c++ from php

hey.I'm kinda expert in php and now i want to start learning c++ but i don't know where to start. i don't wanna read from beginning because I've heard that php is very similar to c and c++.anyone can help? ...

C++: automatic initialization

I find it sometimes annoying that I have to initialise all POD-types manually. E.g. struct A { int x; /* other stuff ... */ A() : x(0) /*...*/ {} A(/*..*/) : x(0) /*...*/ {} }; I don't like this for several reasons: I have to redo this in every constructor. The initial value is at a different place than the variable...

Howto call an unmanaged C++ function with a std::vector as parameter from C#?

Hi! I have a C# front end and a C++ backend for performance reasons. Now I would like to call a C++ function like for example: void findNeighbors(Point p, std::vector<Point> &neighbors, double maxDist); What I'd like to have is a C# wrapper function like: List<Point> FindNeigbors(Point p, double maxDist); I could pass a flat array...

Win32 SetForegroundWindow unreliable

Hey guys, I have a rather complex series of applications which depend on the ability to switch applications in the foreground. My problem is, every 5 or 6 times of switching the applications in the foreground, it simply fails to bring the application forward. GetLastError does not report any issues. Often times I see the correct applica...

How does this work? copying anything into an array of bytes (chars)

struct MyRect { int x, y, cx, cy; char name[100]; }; int main() { MyRect mr; mr.x = 100; mr.y = 150; mr.cx = 600; mr.cy = 50; strcpy(mr.name, "Rectangle1"); MyRect* ptr; { unsigned char bytes[256]; memcpy(bytes, &mr, 256); ptr = (MyRect*)bytes; } printf("X = %d...

Coding conventions for method returns in C++

Hello, I have observed that the general coding convention for a successful completion of a method intended functionality is 0. (As in exit(0)). This kind of confuses me because, if I have method in my if statement and method returns a 0, by the "if condition" is false and thereby urging me to think for a minute that the method had fa...

Runtime Error : RunTime Error : map/set iterators incompatible

void Manager::Simulate(Military* military, Shalishut* shalishut,char* args[]){ Simulation* simulation = Simulation::GetInstance(); Time* time = Time::GetInstance(); multimap<int,Task*>::const_iterator itTasks; itTasks = simulation->GetTasks().begin(); while(itTasks != simulation->GetTasks().end()){ while (itTa...

How to do binary search in a std::multiset without constructing a key_type object?

I have a container like this: // Sort functor struct SortByTime : std::binary_function<const TimeSortableData &, const TimeSortableData &, bool> { bool operator()(const TimeSortableData & a, const TimeSortableData & b) const { return a.GetTime() < b.GetTime(); } }; // Container that sorts by time typedef std::mult...

Intersection of two STL maps

Given that I have two STL maps, say: map<int, double> A; map<int, double> B; I'd like to get the intersection of the two maps, something of the form: map<int, pair<double,double> > C; Where the keys are the values in both A and B and the value is a pair of the values from A and B respectively. Is there a clean STL-like way to go ab...

Parameters in Visual Studio c++ 2010

Hi, I just installed Visual Studio C++ 2010 Express (BTW. great ide). I have to make simple application, but I will open it from command prompt, and I need using parameters. So my question is: how to using parameters in Visual C++ .NET 2010 Express? I need one string and some int. It's special creator to do this or I must change code (i...

error: using typedef-name after class

I can't figure out what the actual problem is with this. typedef struct _actor { ... } _actor, Actor; class Actor { ... }; I get this weird error message actor.cpp:31: error: using typedef-name ‘Actor’ after ‘class’. Any idea what I did wrong here? Thank you :) ...