c++

Valid use of typedef?

I have a char (ie. byte) buffer that I'm sending over the network. At some point in the future I might want to switch the buffer to a different type like unsigned char or short. I've been thinking about doing something like this: typedef char bufferElementType; And whenever I do anything with a buffer element I declare it as bufferEle...

Why is a C++ Vector called a Vector?

The question's pretty self-explanatory really. I know vaguely about vectors in maths, but I don't really see the link to C++ vectors. Thanks! ...

C++ Builder runtime error - cannot focus a disabled or invisible window

On main form I have TPageControl and on all of it's tabs I have corresponding Save buttons which are activated on Alt+S combination. Of course, depending on which tab is opened at the moment, the handler for corresponding Save button should be called; but I get "cannot focus a disabled or invisible window" runtime error if I try to save ...

Repeatable object code generation c++

When I build a project using a c++ compiler, can I make sure that the produced binary is not affected if there were no changes in source code? It looks like everytime I recompile my source, the binary's md5 checksum is affected. Is the time of compilation somehow affecting the binary produced? How can I produce compilation results which ...

Vectors, iterators and std::find

Is there any way to use different types of iterators in different vectors? Or, is there a function that returns the position of element in vector as an integer? std::vector<DWORD>::iterator it; // Iterator // monsterQueue is a <DWORD> vector it = std::find(bot.monsterQueue.begin(), bot.monsterQueue.end(), object); // Check do w...

Looking for an open-source flatfile/xml database C++ library

I'm looking for a light-weight database library that I can compile into a C++ application. Does any such exist? ...

How to create a global handle in C++

I am trying to use a C# class in a C++ project, but Visual Studio will only let me declare a handle (^) to a C# object in a local scope, just inside a function. The only way I got it working was declaring a global pointer to a handle: SUTAdapter::Form1^ *ptForm1; But if then I create an object inside a function and give its address to...

Methods of sharing class instances between processes

I have written a C++ class that I need to share an instance of between at least two windows processes. What are the various ways to do this? Initially I looked into #pragma data_seg only to be disappointed when I realised that it will not work on classes or with anything that allocates on the heap. The instance of the class must be acc...

Assertion error in std:vector used in std::set_difference

I am trying to find the set difference of two vectors, so i do something like this: std::vector<sha1_hash> first_vec, second_vec, difference_vec; // populate first_vec and second_vec ... std::sort(first_vec.begin(),first_vec.end()); std::sort(second_vec.begin(),second_vec.end()); std::set_difference(first_vec.begin(),first_vec.end(),...

Are there optimized c++ compilers for template use ?

C++ templates have been a blessing in my everyday work because of its power. But one cannot ignore the (very very very very long) compilation time that results from the heavy use of templates (hello meta-programming and Boost libraries). I have read and tried quite a lot of possibilities to manually reorganize and modify template code to...

C++: Is there a way to instantiate objects from a string holding their class name?

Hi guys, I have a file: Base.h class Base; class DerivedA : public Base; class DerivedB : public Base; /*etc...*/ and another file: BaseFactory.h #include "Base.h" class BaseFactory { public: BaseFactory(const string }; Base * Create() { if(msClassName == "DerivedA") { return new DerivedA(); } else i...

How to Manage COM Objects in .Net Web Application

A legacy c++ applications with sometimes notorious memory leak issues has to be called from a .Net server based windows application. .Net garbage collection times are not determinable and sometime the c++ object are destroyed or not destroyed "on time" producing unpredictable results and generally crashing the c# web app. What is the b...

Why is my 64-bit C++ app crashing?

I have written a really small 64-bit application that crashes on clean installations of Windows Vista x64. It runs smoothly on my development machine (Windows 7 64-bit), which has Visual Studio 2008 installed. The 64-bit C++ application (unmanaged) is started by a 32-bit .NET application, and crashes immediately afterwards with an acces...

Why is boost so heavily templated?

There are many places in boost where I see a templated class and can't help but think why the person who wrote it used templates. For example, the mutex class(es). All the mutex concepts are implemented as templates where one could simply create a few base classes or abstract classes with an interface that matches the concept. edit aft...

Converting OpenGL Primitives to OpenGLES

I'm trying to convert the following code from OpenGL 1.5 spec. to the OpenGLES 1.1 spec (num_x and num_y are passed into the function by arguments) ::glBegin(GL_LINES); for (int i=-num_x; i<=num_x; i++) { glVertex3i(i, 0, -num_y); glVertex3i(i, 0, num_y); } for (int i=-num_y; i<=num_y; i++) { glVertex3i(-num_x, 0, i); ...

overloading new/delete

i'm making a little memory leak finder in my program, but my way of overloading new and delete (and also new[] and delete[]) doesn't seem to do anything.. void* operator new (unsigned int size, const char* filename, int line) { void* ptr = new void[size]; memleakfinder.AddTrack(ptr,size,filename,line); return ptr; } that w...

ATL Collection of non-trivial objects

I would like to expose an ATL COM collection of CMainClass objects such that it can be accessed by a C#, VB, or C++ client. I don't have a problem setting up the collection itself, but I don't know how to allow the COM clients access to classes A, B, and C. Should I make A, B, & C COM objects with the ones containing a std::list<> each ...

memcmp sort

I have a single buffer, and several pointers into it. I want to sort the pointers based upon the bytes in the buffer they point at. qsort() and stl::sort() can be given custom comparision functions. For example, if the buffer was zero-terminated I could use strcmp: int my_strcmp(const void* a,const void* b) { const char* const one ...

c/c++ changing the value of a const

I had an article, but i lost it, it showed and described a couple of c/c++ tricks that ppl should be careful. One of them interested me but now that i am trying to replicate it I'm not being able to put it to compile. The concept was that it is possible to change by accident the value of a const in c/c++ It was something like this: co...

VCRedist - how can I tell if it's been run?

Hi all, I have an old, old VC++ app that we've ported to VS2005. Our existing users need to get the VC++2005 DLLs, so my app is placing the vcredist_x86.exe on their machines and running it. I check a registry entry under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide\Installations\ which is x86_Microsoft.VC80.MFC blah blah...