c++

Why VC++ Strings are not reference counted?

STL standard do not require from std::string to be refcounted. But in fact most of C++ implementations provide refcounted, copy-on-write strings, allowing you passing string by value as a primitive type. Also these implementations (at least g++) use atomic operations making these string lock-free and thread safe. Easy test shows copy-on...

Are operator overloadings in C++ more trouble than they're worth?

In my experience teaching C++, operator overloading is one of those topics that causes the most grief to students. Even looking at questions here at stackoverflow: for example, make the + operator external or a member? How to handle symmetry, etc., it seems like it's a lot of trouble. When I moved from C++ to Java, I was worried I would...

Compute intersection of two edges

I have this big graph of edges and vertices in 2D space. The big graph is returned by a function computed in a C++ library. I am reading this graph and using it to compute all the intersections of its edges (the lines segements). I use sweep algorithm. For detecting the intersection of two edges I have though some problems. I have 4 diff...

Printing a custom number of header delimiters based on message length

Say I want to print: ============ Some message ============ And: ======================= Other Message long one ======================= The number of "=" changes based on the message length. What is the most efficient way to print this sort of a thing? No boost, just STL please. ...

Clean, efficient algorithm for wrapping integers in C++

/** * Returns a number between kLowerBound and kUpperBound * e.g.: Wrap(-1, 0, 4); // Returns 4 * e.g.: Wrap(5, 0, 4); // Returns 0 */ int Wrap(int const kX, int const kLowerBound, int const kUpperBound) { // Suggest an implementation? } ...

Single XMLHTTPRequest object to make multiple requests.

Does anyone know if there is a way to use a single XMLHTTPRequest object to send multiple asynchronous requests. I can do it with a single request and get a response back from my onreadystatechange() handler. I'm wondering if there's a way to use the same object to send multiple parallel requests but I'm not seeing any way to match a ...

How do I paint with QPainter?

I have started learning Qt recently. I did not get quite clear how can I paint using QPainter class. Let`s say I want just to place a few points in the window: class PointDrawer: public QWidget { Q_OBJECT private: QPainter p; public: PointDrawer(QWidget* obj=0): QWidget(obj), p(this) {} virtual void paintEvent(QPaintEv...

Set app to require elevation?

I'm working on the bootstrap application of a new installer for some of our products. So far, I've been relying on two things that I read about somewhere: Applications whose name contains "setup" or "install" will run elevated by default. Applications that run elevated will launch other applications in elevated mode. Recent testing h...

How would I go about reading/writing a Structs contents to a file in C++ ?

I'm working on a homework project and i'm trying to store inventory data into a file. The inventory data size shouldn't be too large cause technically no one is going to really use it. I need to write these contents to a file: • Item Description • Quantity on Hand • Wholesale Cost • Retail Cost • Date Added to Inventory I am g...

GCC compiler error: "redefinition...previously defined"

I'm getting a lot of " redefinition of x....x previously defined here". Please what does this error means? ...

c++ compiling error related to constructor/destructor definition.

Hello, I'm trying to define the constructor and destructor of my class but I keep getting the error: definition of implicitly-declared 'x::x()'. What does it mean? BestWishes! Part of the code: ///Constructor StackInt::StackInt(){ t = (-1); stackArray = new int[20]; }; ///Destructor StackInt::~StackInt(){ delete[] stackArr...

C++ Using Namespaces to Avoid Long Paths

Hello! I am still learning C++ and I have never really created my own namespaces before. I was experimenting with them and while I got most things to work, there's one thing that I still can't seem to do. I would like to be able to call a static method within a class without typing something like "NameOfClass::method." Here is what I...

Convert Byte Array into Bitset

I have a byte array generated by a random number generator. I want to put this into the STL bitset. Unfortunately, it looks like Bitset only supports the following constructors: A string of 1's and 0's like "10101011" An unsigned long. (my byte array will be longer) The only solution I can think of now is to read the byte array bit ...

I'm trying to read/write the size of multiple structs to a .dat file. I am getting compile errors, what am I doing wrong? (C++)

I've already asked 2 questions kind of related to this project, and i've reached this conclusion. Writing the size of the Struct to the file , and then reading it back is the best way to do this. I'm creating a program for a homework assignment that will allow me to maintain inventory. I need to read / write multiple structs of the same...

Automatic code generation for Objective C to C++ bridge

I am seeking an opinion from the Mac/iPhone developers about a new project. The idea is to start an open source initiative using swig (www.swig.org) for automatically generating the bridge from objective c to c++ so that one can access c++ applications from cocoa/cocoa touch. Apple provides a very good support for mixing objective c and...

Is there some sort of tool or helper to port an MFC/C++ app to OS X/Cocoa?

I have a significant codebase written in MFC and am tasked with creating a port for Mac OS X. I know that I'm going to have to roll up my sleeves at some point and do alot of grunt work to get everything working correctly, but are there any tools out there that might get me partway? ...

I'm getting a C++ compiler error with the '<<' operator. Anyone know why?

I've been working on getting this program complete where it saves multiple structs to a file, can read them back and edit them, then save them all back to a file. I've been working on the logic of this not to mention lots of help from others and a ton of googling hours... now I am getting a compile error. Any help would be very appreciat...

C++ or C# to program mobile barcode device?

I will be developing some applications using mobile barcode scanners and need to choose between C++ and C# for coding on the scanners. I am considering Intermec's CK31 or similar for the combination of wifi, scanning choices, programmability and user interface options. It runs Windows CE .NET 4.2 according to their spec sheet. Intermec...

Implementing A Plugin System in C or C++

What are your tips on implementing a plugin style system? ...

Compile error C++: could not deduce template argument for 'T'

I'm trying to read binary data to load structs back into memory so I can edit them and save them back to the .dat file. readVector() attempts to read the file, and return the vectors that were serialized. But i'm getting this compile error when I try and run it. What am I doing wrong with my templates? ***** EDIT ************** Code:...