c++

binary_search, find_if and <functional>

std::find_if takes a predicate in one of it's overloaded function. Binders make it possible to write EqualityComparators for user-defined types and use them either for dynamic comparison or static comparison. In contrast the binary search functions of the standard library take a comparator and a const T& to the value that should be used...

DirectShow: Video-Preview and Image (with working code)

Questions / Issues If someone can recommend me a good free hosting site I can provide the whole project file. As mentioned in the text below the TakePicture() method is not working properly on the HTC HD 2 device. It would be nice if someone could look at the code below and tell me if it is right or wrong what I'm doing. Introduction...

Weird problem porting application. Undefined reference errors in standard libraries

Hello, I've recently been trying to port a C++ application. I believe I have all of it's dependencies and such and it all compiles. But then, when it goes to link it I get a lot of weird undefined reference errors. /usr/local/lib/libglibmm-2.4.so.7.0: undefined reference to `std::basic_istream<char, std::char_traits<char> >::seekg(long...

llvm clang 2.6: "not using the clang compiler for C++ inputs "

Hello LLVM 2.6 + clang. Trying to compile C++ file and get: clang: warning: not using the clang compiler for C++ inputs How can I start clang in C++ mode? ...

Compiler complains about BOOST_CHECK_THROW on constructor

The following does not compile: class Foo { public: Foo( boost::shared_ptr< Bar > arg ); }; // in test-case boost::shared_ptr< Bar > bar; BOOST_CHECK_THROW( Foo( bar ), std::logic_error ); // compiler error here The implementation of Bar does not matter. The compiler complains, that Foo does not have an appropriate default cons...

How to change the icon in a CTreePropSheet dialog

There is given a SetPageIcon method but it does nothing only the first sets allows ...

Qt4: Locking the mouse cursor in place while manipulating QGraphicsItem...

I'm writing a little GUI utility in Qt4 which uses a QGraphicsScene. One of the items tracks the mouse in the horizontal plane as you move it around, and holding down a modifier key allows you to change the item's rotation. When rotating items I'd like the mouse cursor to change to a curvy arrow (or something) and lock visually in plac...

Hot to get random date in range

I have two dates as strings (dd-mm-yyyy). How can i get a random date between these two dates? ...

how failed constructor roll over to destroy the completed objects?

I know that when a constructor fails, the completed member objects will be destroyed. There is no memory leak. My question is that how does compiler do that? How can compiler know what member is constructed? Does it make any record of it? Does the compiler really destroy everything in this case? How does it guarantee this? ...

C++ : read pixel value with vigra

Hi... can anybody help me ? i am using vigra and i want to read the pixelvalue at any given point. I am an C++ beginner :( ...

How to implement strlen as fast as possible

Assume that you're working a x86 32-bits system. Your task is to implement the strlen as fast as possible. There're two problems you've to take care: 1. address alignment. 2. read memory with machine word length(4 bytes). It's not hard to find the first alignment address in the given string. Then we can read memory once with the 4 by...

Why do we follow opposite conventions while returning from main()?

I have gone through this and this, but the question I am asking here is that why is 0 considered a Success? We always associate 0 with false, don't we? ...

Checking return value of a C++ executable through shell script

I am running a shell script on windows with cygwin in which I execute a program multiple times with different arguments each time. Sometimes, the program generates segmentation fault for some input arguments. I want to generate a text file in which the shell script can write for which of the inputs, the program failed. Basically I want t...

Triple checked locking?

So in the meanwhile we know that double-checked-locking as is does not work in C++, at least not in a portable manner. I just realised I have a fragile implementation in a lazy-quadtree that I use for a terrain ray tracer. So I tried to find a way to still use lazy initialization in a safe manner, as I wouldn't like to quadruple memory ...

insert object into a set

I want to insert a vector into a set like this: set<vector<prmEdge> > cammini; vector<prmEdge> vecEdge; cammini.insert(vecEdge); I have a compilation error like this: prmPlanner.cpp:1285: instantiated from here /usr/include/c++/4.2/bits/stl_algobase.h:853: error: no match for ‘operator<’ in ‘__first1.__gnu_cxx::__normal_iterator<_I...

Problem with name collision in an IDL file

We have an idl file with multiple interfaces defined, two of which have somehting like this: [ object, uuid(79E24BAA-DC12-4caf-91DD-2A4D47FED30A), helpstring("ISomeInterface Interface"), pointer_default(unique) ] interface ISomeInterface: IUnknown { [propget, id(2)] HRESULT SOMEMethod([out, retval] BSTR* pValue)...

Determining the correct size for a C++ array

I need to be able to set the size of an array based on the number of bytes in a file. For example, I want to do this: // Obtain the file size. fseek (fp, 0, SEEK_END); size_t file_size = ftell(fp); rewind(fp); // Create the buffer to hold the file contents. char buff[file_size]; However, I get a compile time error sa...

How much can this c/c++ loop be optimized?

I am a newbie on optimization. I have been reading some reference on how to optimize c++ code but I have a hard time applying it to real code. Therefore I just want to gather some real world optimization technique on how to squeeze as much juice from the CPU/Memory as possible from the loop below double sum = 0, *array; array = (double*...

How would I import a function template using PInvoke?

In my C# code, I need to call a function from a C++ Dll that I wrote.The function is generic. So , should I just import it like this: [DllImport("myDll.dll")] private static extern TypeName functionName<TypeName>( int arg1, int arg2 ); Is this correct syntax? Thanks. ...

Question about running a program at same speed in any computer

I made a program (in C++, using gl/glut) for study purposes where you can basically run around a screen (in first person), and it has several solids around the scene. I tried to run it on a different computer and the speed was completely different, so I searched on the subject and I'm currently doing something like this: Idle function: ...