c++

How to convert C++ class/struct to a primitive/different type/class/struct?

Hi all! I have the following class CppProperty class that holds value: template<typename TT> class CppProperty { TT val; public: CppProperty(void) { } CppProperty(TT aval) : val(aval) { } CppProperty(const CppProperty & rhs) { this->val = rhs.val; } virtual ~CppProperty(void) { ...

How to get OS information whether it be LINUX or WINDOWS?

I'm running "QUdpSocket::ShareAddress" on my QT application but ShareAddress is ignored by windows. So I'm trying to solve this problem by identifying OS at run time. I heard a couple of information about window version indentifier but I couldn't see any solution to solve my problem. If there is any of advice, it would be very appreciat...

boost::multi_index_container with random_access and ordered_unique

Hi, I have a problem getting boost::multi_index_container work with random-access and with orderd_unique at the same time. (I'm sorry for the lengthly question, but I think I should use an example..) Here an example: Suppose I want to produce N objects in a factory and for each object I have a demand to fulfill (this demand is known at...

MSVC: what compiler switches affect the size of structs?

I have two DLLs compiled separately, one is compiled from Visual Studio 2008 and one is a mex file compiled from matlab. Both DLLs have a header file which they include. when I take the sizeof() the struct in one DLL it returns 48, and in the other it returns 64. I've checked the /Zp switch and in both compilations it is set to /Zp8. Wha...

Is there any exist API for URL-encoding in mfc c++?

I am using the following code: CAtlNavigateData navData; CStringA m_strForm = "name=+++&priv=1&password="; navData.SetPostData((BYTE*)(LPSTR)(LPCSTR)m_strForm, m_strForm.GetLength(), QHTTP_FORM_URLENCODE); special symbols such as :"+++" need to do url-encoding, without url-encoding, +++ will turned into space. I need a converer. CSt...

Howto create combinations of several vectors without hardcoding loops in C++?

I have several data that looks like this: Vector1_elements = T,C,A Vector2_elements = C,G,A Vector3_elements = C,G,T ..... up to ... VectorK_elements = ... #Note also that the member of each vector is always 3. What I want to do is to create all combination of elements in Vector1 through out VectorK. Hence in the end we hope to get t...

to dynamically increment from blue to red using C++

Hey all, I want to change the color Blue to Dark Red over a set of know values (like Temperature values for instance). I don't know how to dynamically count up to Blue to Red. Can anyone help me out? I never took an algorithms class so I think that might have something to do with this problem. If you have a better way to do this, t...

Mutex in shared memory

Suppose a process is creating a mutex in shared memory and locking it and dumps core. Now in another process how do i ensure that mutex is already locked but not owned by any process? ...

transition from MFC to QT

Hi Currently our all GUI component are written in MFC, Out build environment is : VC 6 Windows XP I have no idea about : 1) If we can replace all MFC components with QT, without changing build environment ? 2) Will Qt work with VC6 as any other library ? You answers will help me in getting started, In mean time i have i...

How to use speech recognition with/on video file?

How can I code speech recognition engine (Using Microsoft Speech SDK) to "listen" a video file and save the detection into a file? ...

Boost Multi-Index : Composite key of vector and int for hashed indices

Hi, as I've just learned in in my other question, I could use a composite_key for a struct, which has a std::vector and an integer. Now my question is: Can I use this somehow to work with hashed_indecies? Here an example similar to THIS: struct unique_property { //the pair of int and std::vector<int> shall be unique int my_int; ...

What is the maximum length in chars needed to represent any double value?

When I convert an unsigned 8-bit int to string then I know the result will always be at most 3 chars (for 255) and for an signed 8-bit int we need 4 chars for e.g. "-128". Now what I'm actually wondering is the same thing for floating-point values. What is the maximum number of chars required to represent any "double" or "float" value a...

STL: How to check that an element is in a std::set ?

How do you check that an element is in a set? Is there a simpler equivalent of the following code: myset.find(x) != myset.end() ...

Simple C++ logger by using singleton pattern

Due to the flooding examples of implementing logger using Singleton pattern, I just written a simple C++ logger in the same approach for my program. However, since the famous double-checked locking approach is known to be no more thread-safe, I wonder if I should: 1) Forget about the use of Singleton pattern in this case? 2) Continue t...

Initialization of reference member requires a temporary variable C++

struct Div { int i; int j; }; class A { public: A(); Div& divs; }; In my constructor definition, I have the following A::A() : divs(NULL) {} I get the following error: Error72 error C2354: 'A::divs' : initialization of reference member requires a temporary variable ...

Unit testing. File structure

I have a C++ legacy codebase with 10-15 applications, all sharing several components. While setting up unittests for both shared components and for applications themselves, I was wondering if there are accepted/common file structures for this. Because my unit tests have several base classes in order to simplify project/customer speci...

Is it possible to progressively alpha-blend between two textures in one location created with D3DXCreateTextureFromFileInMemoryEx?

I have two textures that are both .jpg, which represent a sky (one during the day, one at night). My question is, is it possible for me to fade one texture into the other? They are created with D3DXCreateTextureFromFileInMemoryEx. How can I perform this kind of transition? I don't wish to create two objects, just change the texture g...

retrieving type returned by function using "typeof" operator in gcc

We can get the type returned by function in gcc using the typeof operator as follows: typeof(container.begin()) i; Is it possible to do something similar for functions taking some arguments, but not giving them? E.g. when we have function: MyType foo(int, char, bool, int); I want to retrieve this "MyType" (probably using typeof ope...

Segmentation fault problem in stl map<>

Hi All, I am not very good at c++ but I have to test a reputation based system. A code fragment is given below which gives me segfault when i run it on ubuntu system. As i wrote in comments two functions "tackleFirstHandInfo()" and "updateReputation()" individually run correctly but when i call one function from the other it crashes. An...

Fixing "error C2065: undeclared identifier"

First off, I'm completely out of my depth here. So the question might be the wrong one to ask, but here goes... As per the accepted answer to this question, I'm trying to compile the bindings for the Audiere library, which are produced by Harald Fielker and available in the mailing list archives. I've opened the .vcproj file in VC++ Ex...