c++

Why does std::map operator[] create an object if the key doesn't exist?

Hi, I'm pretty sure I already saw this question somewhere (comp.lang.c++? Google doesn't seem to find it there either) but a quick search here doesn't seem to find it so here it is: Why does the std::map operator[] create an object if the key doesn't exist? I don't know but for me this seems counter-intuitive if you compare to most othe...

Using C intrinsics and memory alignment difficulties with classes

Ok, so I am just starting to use C intrinsics in my code and I have created a class, which simplified looks like this: class _Vector3D { public: _Vector3D() { aVals[0] = _mm_setzero_ps(); aVals[1] = _mm_setzero_ps(); aVals[2] = _mm_setzero_ps(); } ~_Vector3D() {} private: __m128 aVals[3]; }; So far so good. But when I create a sec...

P/Invoke Interop Assistant: Is this actually correct?

I've got the following structs in C++: (Using pragma pack 1) typedef struct _wfs_cdm_physicalcu { LPSTR lpPhysicalPositionName; CHAR cUnitID[5]; ULONG ulInitialCount; ULONG ulCount; ULONG ulRejectCount; ULONG ulMaximum; USHORT usPStatus; BOOL bHardw...

Template issue causes linker error (C++)

Hi, I have very little idea what's going in regards to C++ templates, but I'm trying to implement a function that searches a vector for an element satisfying a given property (in this case, searching for one with the name given). My declaration in my .h file is as follows: template <typename T> T* find_name(std::vector<T*> v, std::strin...

cross dll debug

Hey, Im using vs 2003. When I try to debug some program that uses several dll files i can debug (put breakpoint - without question mark) only on the cpp files of the project that creates the dll and was the last one that i compiled . breakpoints located on others dlls (that are part of the program and located in the same solution) are m...

Cairo and Qt integration

Hi. I want to use Cairo graphics library whith Qt, but I can't find any documenattion. I just want to make the GUI whith Qt and use Cairo for drawing graphics in a Qt window. Thanks. ...

Programmatically getting per-process disk io statistics on Windows?

I would like to display a list of processes (Windows, C++) and how much they are reading and writing from the disk in KB/sec. The Resource Monitor of Windows 7 has the ability so I should be able to do the same. However I have unable to find a relevant API-call or find anything in the perfmon counters. Could anyone point me in the dire...

Calling a function on STL map element without inserting it first

Is the following code OK? class A { public: A(); void foo(); }; map<int,A> m; m[0].foo(); Or do I have to do the following: map<int,A> m; m[0] = A(); m[0].foo(); And also, can I do this: map<int,A> m; A a = m[5]; And how about access by reference: void foo(A & a); map<int,A> m; foo(m[5]); ...

StartService fails with error code 1053

Hi! I'm trying to start a process on a remote machine. I'm using OpenSCManager(), CreateService(), QueryServiceStatusEx() and StartService() API-s. I'm able to successfully install my process as a serice, but when i'm trying to start it, StartService returns with errorocode 1053 ("The service didn't respond to the start or control reque...

Determining when .NET is about to be loaded in (unmanaged) C++

[ this is getting TLDR...sorry... ] I work on a huge (mostly) C++/MFC application with hundreds of DLLs; it supports a dynamically-loaded "add in" mechanism via COM, thus add-ins can be developed in .NET by using COM interop. Some limited new functionality is developed in .NET w/o using this "add-in" mechanism (although still dynamicall...

Boost deserialization of contained object fails when performed from a constructor, but succeeds otherwise.

Boost deserialization of contained object fails when performed from a constructor, but succeeds otherwise. E.G.: ContainingClass::ContainingClass() { pNA = new objectArray*[NUMBER]; // allocates ptrs // ... pNA[ii] = new objectArray(SIZE);// allocates object array, and object array // has...

Need a fast random generator for c++

Hi guys. I'm trying to do some opt-3 swapping on my TSP generator for euclidian distances, and since I in many cases have more than ~500 nodes, I need to randomly select at least 1 of the 3 nodes that I want to try swapping. So basically I need a random-number function that's fast. (the normal rand() is way too slow) It doesn't have to...

c++ and zlib static library

I am making a c++ (windows devc++) application which downloads a file using libcurl. I have included the libcurl source code and library to mu executable, so no external dll is required. libcurl requires zlib. But I cannot find out how to include it in the executable. As a result zlib1.dll has to be present. Does anybody know how to incl...

C++ static members in class

Hey Guys Is it possible to access to access and use static members within a class without first creating a instance of that class? Ie treat the the class as some sort of dumping ground for globals James ...

What's the low-level difference between a pointer an a reference?

If we have this code: int foo=100; int& reference = foo; int* pointer = &reference; There's no actual binary difference in the reference's data and the pointer's data. (they both contain the location in memory of foo) part 2 So where do all the other differences between pointers and references (discussed here) come in? Does the com...

Does a base class's constructor and destructor get called with the derived ones?

I have a class called MyBase which has a constructor and destructor: class MyBase { public: MyBase(void); ~MyBase(void); }; and I have a class called Banana, that extends MyBase like so: class Banana:public MyBase { public: Banana(void); ~Banana(void); }; Does the implementation of the new constructor and destructor...

error: cast from 'void*' to 'int' loses precision

I have a function with prototype void* myFcn(void* arg) which is used as the starting point for a pthread. I need to convert the argument to an int for later use: int x = (int)arg; The compiler (GCC version 4.2.4) returns the error: file.cpp:233: error: cast from 'void*' to 'int' loses precision What is the proper way to cast this...

How do I append elements with duplicate names using MSXML & C++?

I am write some code to update a XML DOM using MSXML4 & C++. I need a method that appends a child element to a parent element. The code I have written below works until the title of the child matches the title of another child under the parent. I cannot change the title of the children so I need to find a way to append them to the par...

In C++, can you manually set the failbit of a stream? How?

I am overloading the input stream operator for use with a Time class and would like to manually set the failbit of the input stream if the input doesn't match my expected time format (hh:mm). Can this be done? How? Thanks! ...

How to UDP send and receive on same port?

I need to be able to send and receive UDP packets on the same port. I am able to listen, on say port 5000, but my send uses a random high port. The system I am working written in VB with does this and my need is to write a UDP responder for debugging various protocol issues. I am using the Open Source C++ Sockets Library from http://www...