c++

C++ Template abuse question - Augmenting floats with additional type information

I had an idea motivated by some of the documentation I read in the tutorial of the boost MTL library. The basic premise is that I would like to use templates to give me compile time type checking errors for things that are otherwise the same. Namely, lets say I have two units of measurement, Radians and Degrees. The most obvious way to...

Using a struct member in STL algorithms

#include <iostream> #include <vector> #include <iterator> using namespace std; struct Point { int x; int y; Point(int x, int y) : x(x), y(y) {} }; int main() { vector<Point> points; points.push_back(Point(1, 2)); points.push_back(Point(4, 6)); vector<int> xs; for(vector<Point>::ite...

Parameter choice for copy constructor

I was recently asked in an interview about the parameter for a copy constructor. [Edited] As a designer of C++ language implementing copy constructor feature, why would you choose constant reference parameter over a const pointer to a const object. I had a few ideas like since a pointer can be assigned to NULL which probably doesn't m...

"Unable to resolve..." in NetBeans 6.7.1, Linux, C++

I am working with a small group on a C++ project in NetBeans. For some reason, NetBeans is reporting things like "string", "endl", "cout" as "Unable to Resolve" even though the correct libraries have been included. The project compiles and runs as expected, so at the end of the day, it is no big deal, it is just that having everything ...

How to write a function that takes an iterator or collection in a generic way?

I've been a Java programmer almost exclusively for the past 8 years or so, and recently I've been playing with C++ again. Here's an issue that I've come up against with regards to iterators in C++ STL and Java. In Java, you can write a method that takes an iterator like this: void someMethod(Iterator<String> data) { // ... } You ...

How to set the picturebox style using SendMessage in win32

Hi, i want to set the style of picturebox using sendmessage in win32. i want a sample piece of code with enum values of setting style.. please please suggest me... i will be thank full to u guys.. please help me. ...

Multithreaded single-reader single-writer fifo queue

I need a queue for passing messages from one thread (A) to another (B), however ive not been able to find one that really does what I want, since they generally allow adding an item to fail, a case which in my situation is pretty much fatal since the message needs to be processed, and the thread really cant stop and wait for spare room. ...

C++ and process memory protection

I know that WinAPI has built-in hacking functions. I even used them in C# with Pinvoke... To hack Minesweeper... It was easy... So... How i could protect my application from process memory editing, deny DLL injecting and other hacking ways. HOW?! Hope WinAPI has something like void DontTouchMeOrIWillTerminateYou(bool protect)... ...

How to use enums as flags in C++?

Treating enums as flags works nicely in C# via the [Flags] attribute, but what's the best way to do this in C++? For example, I'd like to write: enum AnimalFlags { HasClaws = 1, CanFly =2, EatsFish = 4, Endangered = 8 }; seahawk.flags = CanFly | EatsFish | Endangered; However, I get compiler errors regarding int/enum...

How to avoid entering library's source files while debugging in Qt Creator with gdb?

How can I configure Qt Creator and/or gdb so that while debugging my program using Qt libraries the debugger would avoid stepping into Qt's source files? ...

initializing a C++ std::istringstream from an in memory buffer ?

I have a memory block (opaque), that I want to store in a Blob in mySQL through their C++ adapter. The adapter expects a istream: virtual void setBlob(unsigned int parameterIndex, std::istream * blob) = 0; So my question is: how can I create a std::istream from this memory block (typed as char*). It's not a string as it is not null-te...

operator overloading in C++

Besides 'new', 'delete', '<<' & '>>' operators, what other operators can be overloaded in C++ outside of a class context? ...

Convenient strategies for assertion checks.

Some asserts are costly, some are better turned off at production code. At least it is not clear that assertions should be always enabled. In my application I would like to be able to turn on/off part of assertions on per-file or per-class basis. How to do it in C++? ...

Can I send an operator as parameter to a function?

For example I can write in c: int sum(int a, int b); void print(int a, int b, int (*f)(int, int)); The question is can I send an operator? print(12, 13, sum); // print(12, 13, operator +); compilation error ...

Opinions about list item and its class design

I'm currently designing a list widget to add to my widget engine. Since every elements visual aspects are defined outside the code I can reuse most of the code base. For instance tab buttons are actually checkboxes. New templates take time to implement since they should have at least a viewer in design application. I already have an imp...

Why there is no std::copy_if algorithm?

Is there any specific reason for not having std::copy_if algorithm in C++ ? I know I can use std::remove_copy_if to achieve the required behavior. I think it is coming in C++0x, but a simple copy_if which takes a range, a output iterator and a functor would have been nice. Was it just simply missed out or is there some other reason behin...

Advice on Abstract Factory, DLL Exporting and Smart Pointers

Okay guys, this is a follow up to one of my previous questions and I have come up with a possible solution to my project and I need some advice or guidance if I have this right. Basically my project is a library to be used and compiled on both Linux and Windows, the Linux part isn't much of an issue, its Windows. My library consists ma...

Disk Space? (used/free/total) how do I get this? in C++...

Disk Space? (used/free/total) how do I get this? in C++... thanks just for reading. ...

Writing a C# Variable Length Structure to Binary and Reading it in in C++?

Okay, so i am continuing to work on my little game engine to teach me C#/C++ more. Now i am attempting to write a way of storing data in a binary format, that i created. (This is learning, i want to do this my self from scratch). What i am wondering what is the best way of dealing with variable length arrays inside a structure when readi...

Writing to a file using echo

void EDataset::PrintErr(const NDataString& ErrMsg){ system("echo " + $ErrMsg + " >> err.txt"); .... code .... } It prints blank line as the value of ErrMsg. How come? ...