c++

std::set with user defined type, how to ensure no duplicates.

Hello. So I have an std::set which needs to keep specific ordering as well as not allowing duplicates of a user defined (by me) type. Now I can get the order to work correctly by overloading the '<' operator in my type. However, the set does not appropriately detect duplicates, and to be honest I'm not entirely sure how it does this inte...

Which is the best C++ compiler?

Can a C++ compiler produce a not so good binary? You can think here of the output's robustness and performance. Is there such a thing as the "best" C++ compiler to use? If not, what are the strong points, and of course, the not-so-strong (known Bugs and Issues) points, of the well-known compilers (g++, Intel C++ Compiler, Visual C++, etc...

Add Library to Visual Studio 2008 C++ Project

I'm completely new to Visual Studio and I'm having some trouble getting a project started with Visual Studio 2008. I'm experimenting with MAPI, and I'm getting error messages like this when I go to build the project: "unresolved external symbol _MAPIUninitialize@0 referenced in function _main" I know I need to link to MAPI32.lib, but ...

Boost::regex issue, Matching an HTML span element

Dears, I don't get it. I created this regular expression: <span class="copy[Green|Red].*>[\s]*(.*)[\s]*<\/span> to match certain parts of HTML code (a part between spans). For instance the following: <span class="copyGreen">0.12</span> <span class="copyRed"> 0.12 </span> Now, this works beautifully with RegexBuddy and others, ...

Lua bindings to C++ and garbage collection.

Ok, here's a problem I'm having. I have Lua bindings to a rendering engine that has an internal render manager that keeps its own track of pointers for the render scene and manages them. The problem is that when I'm using it from Lua, if i don't keep a Lua reference to every single object i add to the C++ render manager, it starts to ga...

Copying text from a textbox in C++

Specifically, a program is running and I want to extract the text from a text box inside the program. Generally, what methods/topics should I be using to "get inside" another .exe running on my system and extract data from a text box inside it using C++? I just want a pointer towards the way in which I might achieve this. Thanks. ...

Efficiency of c++ built ins.

I am fairly new to C++, having much more C experience. I am writing a program that will use the string class, and began to wonder about the efficiency of the "length()" method. I realized though that I didn't have a good answer to this question, and so was wondering if the answer to this and similar questions exist somewhere. While I a...

Run an Application in GDB Until an Exception Occurs

I'm working on a multithreaded application, and I want to debug it using GDB. Problem is, one of my threads keeps dying with the message: pure virtual method called terminate called without an active exception Abort I know the cause of that message, but I have no idea where in my thread it occurs. A backtrace would really be helpful....

MSVC: union vs. class/struct with inline friend operators

This piece of code compiles and runs as expected on GCC 3.x and 4.x: #include <stdio.h> typedef union buggedUnion { public: // 4 var init constructor inline buggedUnion(int _i) { i = _i; } friend inline const buggedUnion operator - (int A, const buggedUnion &B) { return buggedUnion(A - B.i); } ...

C++: TR1 vs GSL vs Boost for statistical distributions?

Hi, in my previous post I was asking how to generate numbers following a normal distribution. Since I have also other distributions to generate and I saw 3 libraries might provide them (GSL, TechnicalReport1(doc link?), Boost), I was wondering which one you would choose. As a side note: the reference platform for my application is a ...

Set IP_HDRINCL to setsockopt function in win32

Hi, I'm fighting with raw sockets in Win32 and now I'm stuck, the soetsockopt funtion give me the 10022 error (invalid argument), but I think I pass the correct arguments... of course I'm wrong u_u' sock = socket(AF_INET,SOCK_RAW,IPPROTO_UDP); if (sock == SOCKET_ERROR) { printf("Error socket(): %d", WSAGetLastError()); return; } ch...

Should I use std:: and boost:: prefixes everywhere?

In my C++ code I don't use the declarations using namespace std; or using namespace boost;. This makes my code longer and means more typing. I was thinking about starting to use the "using" declarations, but I remember some people arguing against that. What is the recommended practice? std and boost are so common there should be no much ...

Autocompletion in Vim

In a nutshell, I'm searching for a working autocompletion feature for the Vim editor. I've argued before that Vim completely replaces an IDE under Linux and while that's certainly true, it lacks one important feature: autocompletion. I know about Ctrl-N, Exuberant Ctags integration, Taglist, cppcomplete and OmniCppComplete. Alas, none o...

Covariant virtual functions and smart pointers

In C++, a subclass can specify a different return type when overriding a virtual function, as long as the return type is a subclass of the original return type (And both are returned as pointers/references). Is it possible to expand this feature to smart pointers as well? (Assuming a smart pointer is some template class) To illustrate:...

Is assert and unit-testing incompatible?

Hello, I have some concerns related to the fact of testing some functions containing the assert macro from assert.h. If the assert fails the test fails also. This leaves me with some test cases that will never work. For example a function instead of indicating failure (return false or something similar) asserts. Is there a solution f...

Memory-efficient C++ strings (interning, ropes, copy-on-write, etc)

My application is having memory problems, including copying lots of strings about, using the same strings as keys in lots of hashtables, etc. I'm looking for a base class for my strings that makes this very efficient. I'm hoping for: String interning (multiple strings of the same value use the same memory), copy-on-write (I think this...

Just adding some documentation triggers recompilation: Is there a solution?

Sometimes, when I look through my header files I'd like to add something little to the (doxygen) documentation. That might be a quick note about the use of some function parameter, or just fixing a little typo. But then I think: Oh no, that'll trigger a recompile on the next make call! And for certain basic headers the whole project wou...

Profiling instructions

I want to count several cpu instructions in my code. e.g. I would like to know how many additions, how many multiplications, how many float operations, how many branches my code executes. I currently use gprof under Linux for profiling my c++ code but it only gives the number of calls to my functions, and I manually estimate the number o...

Refusing connection from a host

I'm writing a simple tcp server application using sockets. As far as I know I can obtain the client's ip address and port after calling accept(). Now lets assume I have a banlist and I want to ban some ip addresses from my server. Is there a better way than accepting the connection and then dropping it? Is there a way to get the clien...

How to quit a C++ program?

How do I quit a C++ program. Which function is called to end a program and which values does the method take? To clarify I want to exit a C++ program from within my code. And I may want to exit the program outside of the main function of this program. ...