c++

Source code needed for calculating quaternions

I have gyroscope + accelerometer data at each time period T. I want to calculate the rotation of the object at each time - it can rotate on its axises. So I've read that it is convenient to represent the rotation of the system in terms of quaternions (not in Euler angles). Is there any source code that can transform from angular veloci...

Is it safe to read a single c++ std::map object by different threads simultaneously without synchronization mechanisms?

I have a global object holding several c++ std::map objects. This object is supposed to be read only in a multithreaded environment. But i'm not sure whether there is any write operation when a C++ std::map object is being read within the implementation of std::map. The IDE is Visual Studio 2008. Should I provide some synchronization mec...

C++: Container of original pointers

Hello folks, I need to store references to instances of derived classes in C++. I considered using a vector of shared_ptrs to the base class (for it needs to hold different types of derived classes), however, it's important that the container holds the original pointers, which is not the case with vectors (or other stl containers), if I...

template+floating point non type

Section 4.3 of C++ Templates states 'Not being able to use floating-point literals (and simple constant floating-point expressions) as template arguments has historical reasons.' Similarly, $14.1/7 states - "A non-type template-parameter shall not be declared to have floating point, class, or void type. [ Example...

Why can't compiler optimize these 2 statements out?

Is there any reason that the compiler cannot optimize the following 2 statements out in main even I turned on fully optimization in Visual C++? Any side effect to access a int variable in memory? int _tmain(int argc, _TCHAR* argv[]) { volatile int pleaseOptimizeMeOut = 100; (pleaseOptimizeMeOut); return 0; } ...

What is virtual inheritance?

Possible Duplicate: In C++ virtual base class? The virtual keyword is used to remove the ambiguity, but how does it actually work? I have four classes: a, b, c, and d. I am doing: class a {public int a;}; class b: virtual public a {}; class c: virtual public a {}; class d:public b,public c {}; This works, but what actu...

OpenMP Parallelizing code-block inside a for loop ?

Greetings all, I want to run the code block inside the loop ,in seperate OpenMP thread. Have I defined correct OpenMP directives in the following code snippet: #ifdef OPENMP_ENABLE #pragma omp parallel for #endif for(int i=0;i<numOfSlices;i++){ // Entire block inside this loop should be fun in new OpenMP t...

Templates :Name resolution:Dependent types: -->can any one tell some more examples for this statement?

This is the statement from ISO C++ Standard 14.6.2.1: Dependent types : A type is dependent if it is — a template parameter,#1 — a qualified-id with a nested-name-specifier which contains a class-name that names a dependent type or whose unqualified-id names a dependent type,#2 — a cv-qualified type where the cv-unqualified type is d...

linux tool to list all functions in a source file?

I am looking for a command line utility on *nix, that can dump the names of all the functions, classes etc. defined in a file(C/C++/Java) ...

run out of system resource (execute many programs in a shell script)

Hi guys I'm running a shell script on the university's server. In this shell script, I will execute java, c, c++, python and perl programs. Because every program will be executed many many times(I'm a teaching assistant and will test the students' programs with many different inputs). The server always gives me an error: "running out of...

Why doesn't shared_ptr have a virtual descructor? (and how can I get around this?)

I wanted to make a special version of shared_ptr that would perform specific operations when it was created or destroyed, but my plans appear to be foiled by the realization that shared_ptr's destructor is non virtual, meaning when I override it, my pointers never get cleaned up when the last instance of them are destroyed. The only al...

using OpenMPI or MPICH2 with Boost MPI using Win and Linux machines together

hi All These days I am approaching MPI world. I am willing to use Boost MPI libraries probably with OpenMPI or MPICH2 ( even if with MPICH2 still I am not sure whether it will work fine because of some post I read around ). My real question is the following: with these 2 libraries and Boost MPI on top of it, is it possible to combine r...

constant references with typedef and templates in c++

I heard the temporary objects can only be assigned to constant references. But this code gives error #include <iostream.h> template<class t> t const& check(){ return t(); //return a temporary object } int main(int argc, char** argv){ const int &resCheck = check<int>(); /* fine */ typedef int& ref; const ref error = check<int...

Rank in c sharp

after filling an array about 20 elements with students marks then rank 1 to highest marks of all student then increase rank to 2 to next highest marks of all student or remaining students this just class management please help me to write algorithm in c# or C or C++ or java ...

How to convert a char array into string based hex-stream (ostringstream)

Hi, in C++ (on Linux with gcc) I'd like to put a byte array (vector<unsigned char>) to a ostringstream or a string. I know that I can use sprintf but it doesn't seem to be the best way to use char* also. btw: this link did not help Edit: All answer work so far. But I did not meantion, that I'd like to convert the bytes/hex-values int...

[C++] Access members directly or always use getters

Note: C++ specific question I personally find it weird/ugly when a class uses a getter to access its own member data. I know the performance impact is none but I just don't like to see all those method calls. Are there any strong arguments either way, or is it just one of those things that's personal preference and should be left to eac...

How to SELECT whole table with OTL, and save it to file?

Here is the problem, I dont know how many attributes or which type are the attributes in table and I need simple select statment like: SELECT * FROM TABLE1; to write down to file. And this need to be done with otlv4 wrapper. Please help. otl_stream i(50, // buffer size "select * from test_tab where f1>=:f<int> and f1...

How to resolve dependent classes?

I have two classes which depend on each other. I've solved this problem before but I can not for the life of me remember how to fix this. My simplified code is this: struct MenuOption{ string Text; int Choice; bool UseSubMenu; Menu SubMenu; }; class Menu{ public: Menu(MenuOption optionlist[],int optioncount); }; ...

Can C++0x still explicitly allocate with global operator new?

Wikipedia states: A type can be made impossible to allocate with operator new: struct NonNewable { void *operator new(std::size_t) = delete; }; An object of this type can only ever be allocated as a stack object or as a member of another type. It cannot be directly heap-allocated without non-portable trickery. (Since place...

intializing a structure

Hello, g++ 4.4.3 I have the following structure from a API guide: typedef struct NETWORK_INFO { int network_id; int count; } NETWORK_INFO, *NETWORK_INFO; And in the source code they are doing this: NETWORK_INFO net_info = {}; Is the 2 curly braces initializing the object of the structure? But what would it initialize the ...