c++

In C++, why does true && true || false && false = true?

I'd like to know if someone knows the way a compiler would interpret the following code: #include <iostream> using namespace std; int main() { cout << (true && true || false && false) << endl; // true } Is this true because && has a higher precedence than || or because || is a short-circuit operator (in other words, does a short cir...

Help with Linker error LNK2038 !

I am trying to port a small app of mine from Win XP and VS 2005 to Win 7 and VS 2010. The app compiles and runs smoothly in Debug mode, however in Release mode I get the following error : pcrecpp.lib(pcrecpp.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in LoginDlg.obj The wor...

Abstract classes - syntax help

I am having a bit of a problem with abstract classes. I have a bunch of classses. In the StackAsLinkedList.h class i have a linked list of pointers to Objects as seen here LinkedList<Object*> list; The syntax is wrong and i dont know what to do. if i name it a int or char i get the same syntax error.. I am fairly new to ADT / class hi...

Seamless scrolling tilemaps

I'm working on a top-down rpg, and want to implement seamless scrolling maps. That is, as the player explores the world, there is no loading screen between maps and no "doors" to the next area. I have two ways to break down the world. At the top level, I have "zones" which is simply a collection of 9 "maps"(These zones are only represe...

Linking libpng with Borland c++

I made a program on mac osx using opengl and dynamically linking libpng. Im now trying to port it to windows. Whenever I try to compile and link my ported program in borland it gives me this error and about 10 more that are the same but with a different '_png_create_read_struct' Error: Unresolved external '_png_create_read_struct' re...

Clearing terminal in Linux with C++ code.

Okay, I have been researching on how to do this, but say I am running a program that has a whole bit of output on the terminal, how would I clear the screen from within my program so that I can keep my program running? I know I can just type clear in terminal and it clears it fine, but like I said, for this program it would be more bene...

protocol buffers and actual transport options - sockets or middleware

Hi there, I am developing a client/server application for which I am evaluating a few options for the communications layer. As part of this communication framework, I am contemplating using google's protocol buffer (PB) for representation of the transport data instead of re-inventing my own binary structure. Now coming on to the actua...

Suppress system("ping") output in C++

Hi guys, I have written a simple program that pings three sites and then reacts to whether they are reachable or not. My question is: can I suppress system("ping ")'s output? I have written my code in C++ as I know that language the best. Currently the code opens the ping.exe running the system command. If I can prevent the output from...

Can 2 pthread condition variables share the same mutex?

I went through the documentation in http://www.opengroup.org/onlinepubs/009695399/functions/pthread_cond_wait.html but this is not mentioned explicitly. Any prompt response will be very appreciated. ...

How do I make my dependencies call my global operator new?

Hi, I have a test app that is linked with some DLLs (or .so's). In my main app I defined a global new/delete like this: void* operator new(size_t n) { .... } void operator delete(void* p) { ... } But I noticed the operators are only called for things I allocate in my main app, but not if one of the DLLs does. How do I make ...

How to prevent arrow keys from changing the UI state?

I am developing a Tetris game using C++ in combination with the plain old WinAPI, GDI and GDI+. The applications window contains a few UI controls along with a static control that is used for painting the game state. I am using a keyboard hook so that I can respond to the arrow keys to move the current block and the space bar to drop the...

Return from a C++0x lambda caller directly

I've just rewritten the following C89 code, that returns from the current function: // make sure the inode isn't open { size_t i; for (i = 0; i < ARRAY_LEN(g_cpfs->htab); ++i) { struct Handle const *const handle = &g_cpfs->htab[i]; if (handle_valid(handle)) { if (handle->ino == (*inode)->i...

Explicit template specialization issue

Hi, i have below code template <class T> class Test { public: template<class U> void f(); //generic function template<> void f<char>(); //Specialization for char. }; template <class T> template<class U> void Test<T>::f() //Definition of generic function { } template<> template<> void Test<char>::f<char>(){} //Definition o...

How to generate truly random numbers (NOT pseudo) in Linux

Hello, What is the (best) way to create a secure random numbers in Linux (C/ C++ code), more random than the general rand() results, and not pseudo as OpenSSL BN_rand? In Windows I found CryptGenRandom() as a good option. Is there any equivalent in Linux? Thank you in advance. ...

Save a webpage to memory in C++ using cURL

I have been successful in saving a webpage to memory using a structure. But is it possible do it using a class? I am having trouble accessing the write data function inside the class. Since I am writing from my mobile, I am unable to insert code snippets. ...

How can templated code find the length of a string whose type is a template parameter, in C++?

Consider this code: template <typename T> class String { public: ... String(T* initStr) { size_t initStrLen; if (initStr != NULL) { printf_s("%s\n", typeid(T) == typeid(char) ? "char" : "wchar_t"); if (typeid(T) == typeid(char)) { strlen((T*)initStr); } else if (typeid(T) == typeid(wchar_t)) { wcsl...

stl allocator, copy constructor of other type, rebind

The STL allocators require this constructor form (20.1.5): X a(b); with the requirement that Y(a) == b; In the standard implementation this implies, and is implemented as: template<class U> allocator( const allocator<U> & o ) throw() I'm having trouble understanding why this requirement exists. I understand that allocators should b...

Free GUI framework to create a single exe?

I'm looking for free and easy GUI framework that let me create single exe without dependency (like .Net framework) and to be not GPL as a side note .. im using Qt and its great but i have to be LGPL to use it that means lots of fat dlls . is there any alternative? p.s how did the Dropbox client made of? i know its python but how did...

how to create an allocator for std::map using a pool of objects

This is a followup from http://stackoverflow.com/questions/4062503/stl-allocator-copy-constructor-of-other-type-rebind I am using std::map and want a custom allocator that can reuse the storage for the internal nodes. The items being stored are pointers, so I'm not talking about reusing them, just the internal allocations for the map. ...

Is it possible to use boost::serialization with managed class?

We have a lot of native c++ classes that are serialized perfectly using boost::serialization. Now we want to change some of their member fields to property, so we could use them in PropertyGrids. When we changed the class definiction to ref class X, we got a huge number of these compilation errors: #1: error C2893: Failed to specialize...