c++

MSVC enum debugging

Is there a quick way of outputting the names of enumerated values? I suppose you know what I mean, and at all this isn't possible as of course all of this data becomes irrelevant during compile process, but I'm using MSVC in debugging mode, so is it possible? ...

Better way to write an object generator for an RAII template class?

I would like to write an object generator for a templated RAII class -- basically a function template to construct an object using type deduction of parameters so the types don't have to be specified explicitly. The problem I foresee is that the helper function that takes care of type deduction for me is going to return the object by ...

How does server management software work?

How does server management software work? I was reading about those software and I found that they can monitor CPU speed/temperature. How one can do this in C++? ...

C++ STL: Array vs Vector: Raw element accessing performance

I'm building an interpreter and as I'm aiming for raw speed this time, every clock cycle matters for me in this (raw) case. Do you have any experience or information what of the both is faster: Vector or Array? All what matters is the speed I can access an element (opcode receiving), I don't care about inserting, allocation, sorting, et...

Reading data from a socket

I am having issues reading data from a socket. Supposedly, there is a server socket that is waiting for clients to connect. When I write a client to connect() to the server socket/port, it appears that I am connected. But when I try to read() data that the server is supposedly writing on the socket, the read() function hangs until the...

Syntax explanation

In code: struct tagPaint { }Paint,//<<<--------------what's this (Paint)? *pPaint;//<<<-------------and this(*pPaint)? I mean do I declare variable with name Paint of type tagPaint and pointer called pPaint to tagPaint? Thanks. ...

c++ malloc segmentation fault

I have a problem about malloc(). It is weird. My code is in the following. I use random generator to generate elements for an array. The array is opened by malloc(). If the array size is smaller than 8192, it is OK. If the size is larger than 8192, it shows segment fault. void random_generator(int num, int * array) { srand((unsigne...

How to Embed/Link binary data into a C++ DLL

So I have a Visual Studio 2008 project which has a large amount of binary data that it is currently referencing. I would like to package the binary data much like you can do with C# by adding it as a "resource" and compiling it as a DLL. Lets say all my data has an extension of ".data" and is currently being read from the visual studio...

Question about c++ memory management

Instead of int *i = new int; ... delete i; could I just do this? int i; ... delete &i; ...

How can I store an inventory-like list of numbers?

I've got a list of number that I need to keep track of. The numbers are loosely related, but represent distinctly different items. I'd like to keep a list of the numbers but be able to refer to them by name so that I can call them and use them where needed easily. Kind of like an inventory listing, where the numbers all refer to a part I...

Nested bind expressions

This is a followup question to my previous question. #include <functional> int foo(void) {return 2;} class bar { public: int operator() (void) {return 3;}; int something(int a) {return a;}; }; template <class C> auto func(C&& c) -> decltype(c()) { return c(); } template <class C> int doit(C&& c) { return c();} template <cl...

How to share classes between DLLs

I have an unmanaged Win32 C++ application that uses multiple C++ DLLs. The DLLs each need to use class Foo - definition and implementation. Where do Foo.h and Foo.cpp live so that the DLLs link and don't end up duplicating code in memory? Is this a reasonable thing to do? [Edit] There is a lot of good info in all the answers and comme...

How safe and reliable are C++ String Literals?

So, I'm wanting to get a better grasp on how string literals in C++ work. I'm mostly concerned with situations where you're assigning the address of a string literal to a pointer, and passing it around. For example: char* advice = "Don't stick your hands in the toaster."; Now lets say I just pass this string around by copying pointer...

what is the reason for the difference between setprecision (12) and setprecision (012) for example,in c++?

In c++ when you write setprecision (12) for example, 12 is in the base of 10 but when you write it like setprecision (012) it is an octal number,why? ...

Compiling Freetype for iPhone SDK (XCode)

I was wondering if anyone knew how to configure FreeType in XCode for the iPhone SDK. I have been trying with no success. Thanks ...

Is it possible to use boost::bind to effectively concatenate functions?

Assume that I have a boost::function of with an arbitrary signature called type CallbackType. Is it possible to use boost::bind to compose a function that takes the same arguments as the CallbackType but calls the two functors in succession? I'm open to any potential solution, but here's a... ...Hypothetical example using some magi...

Malloc function in C++

I am transitioning to C++ from C. In C++, is there any use for the malloc function? Or can I just declare it with the "new" keyword. For example: class Node { ... } ... Node *node1 = malloc(sizeof(Node)); //malloc Node *node2 = new Node; //new Which one should I use? ...

Why does C++ linking use virtually no CPU? (updated)

On a native C++ project, linking right now can take a minute or two, yet during this time CPU drops from 100% during compilation to virtually zero. Does this mean linking is primarily a disk activity? If so, is this the main area an SSD would make big changes? But, why aren't all my OBJ files (or as many as possible) kept in RAM after co...

Video Game Bots?

Something I've always wondered, especially since it inspired me to start programming when I was a kid, was how video game bots work? I'm sure there are a lot of different methods, but what about automation for MMORPGs? Or even FPS-type bots? I'm talking about player-made automation bots. ...

Are Bitsets actually Bools?

In C++, are bitsets actually a set of bools? Doesn't this defeat the purpose of using a BitSet because bools are 32 bits (I think...)? ...