c++

C++ Dynamic memory allocation

I'm just learning about dynamic memory allocation, but there is one thing i'd like to be explained. One use for dynamic allocation is for dynamic sized arrays, and thats clear to me. Another use is for normal objects. What is a situation one should use it? Is it because normally objects are pushed on the stack, and could be popped of? ...

boost serialization NVP macro and non-XML-element characters

When using the BOOST_SERIALIZATION_NVP macro to create a name-value pair for XML serialization, the compiler happily allows the following code to compile, even though the element name is not a valid XML element and an exceptions is thrown when trying to actually serialize the object into XML: BOOST_SERIALIZATION_NVP(_member[index]) An...

Checking if Registry Value exists Visual C++ 2005

Hi There, Im trying to code a Visual C++ 2005 routine that checks the registry for certain keys/values. I have no trouble in writing code using c# but I need it in C++. Anybody know how to do this using c++ in vs2005. Many thanks Tony ...

Code optimization bibles

Hello, What are the most highly regarded books on optimization / performance tuning of C/C++ code? ...

Beginning C++ problem; cannot instantiate abstract class (C2259 in VS)

I'm attempting to create a concrete instance of the IAudioEvents COM interface (available in Vista and later). This is my first foray into COM programming, so I'm probably just doing something stupid here. Anyway, the following code fails to compile with "C2259: 'AudioEndpointVolumeNotifierImpl' : cannot instantiate abstract class". C...

C++ standard list and default-constructible types

Why is that the single parameter constructor of std::list<T> requires T to be a default-constructible type? I mean the following code does not compile. struct Foo { // does not have default constructor. Foo (int i) {} } int main(void) { std::list<Foo> l(10); } It seems possible to use the construct and destroy idioms as they hav...

Problem in calling a C++ dll function from C#

Hello, This is my 3rd thread concerning a blowfish problem in C#.Despite the fact I cannot have blowfish implemented in my application, I decided to use it as an external C++ dll. Please note I've tried Blowfish.NET and any other, the problem is that I'm translating code from C++ to C# and the C# code must do exactly the same as the C++...

Qt XML Input

I'm trying to input data from an XML file in a C++ program using the Qt tool kit. My XML data is formatted as follows: `<item> <title>title<\title> <tree_loc1>0<\tree_loc1> <parent>parent<\parent> <description>description<\description> <other_info>other info<\other_info> <location>location<\location> <last_mo...

Why does the C++ map type argument require an empty constructor when using []?

See also http://stackoverflow.com/questions/695372/c-standard-list-and-default-constructible-types Not a major issue, just annoying as I don't want my class to ever be instantiated without the particular arguments. class MyClass { public: MyClass(MyType1 t); MyType2 &operator[](int index); } map<int, MyClass> myMap; Th...

Qt PDF Tutorial?

Where can I find a Qt tutorial in PDF format. I have looked all over google but can't find one. I need to be able to read it offline as I can't always be on the internet. Thanks! ...

Thought experiment with __stdcall and corrupted stack (C++)

My mind was wandering today on the topic of function pointers, and I came up with the following scenario in my head: __stdcall int function (int) { return 0; } int main() { (*(int(*)(char*,char*))function)("thought", "experiment"); return 0; } AFAIK this code would corrupt the stack, so what types of issues could I be loo...

C++ STL map::erase a non-existing key

Regarding the C++ STL map, erasing by key:- size_type map::erase ( const key_type& x ); Is it legal to erase a non-existing key? i.e. is the snippet below ok? map<char,int> mymap; mymap['c']=30; mymap.erase('c'); mymap.erase('c'); mymap.erase('D'); Cheers ...

For a NULL pointer, should I use NULL or 0?

Duplicate Do you use NULL or 0 for pointers in C++? When dealing with NULL pointers one can do this if(ptr != NULL){ ... } or this if(ptr != 0){ ... } Are there reasons to prefer one over the other in C++? ...

c++ exit loop based on keyboard input

Is it possible to exit a C++ loop based on keyboard input without actually having to input something each iteration? For instance while(checkkeyboardinput != 'q') { do work } I feel that this is very easy, but google isn't helping me, and I can't remember how to do this. Thanks for the help. EDIT: I'm using VS2008 ...

What happens when you close a c++ console application

I guess the question says it all, but, what happens if someone closes a c++ console app? As in, clicks the "x" in the top corner. Does it instantly close? Does it throw some sort of exception? Is it undefined behavior? ...

Run-Time Check Failure #0 loading QueryFullProcessImageName from kernel32.dll

I have an application that needs to run both on WinXP and Vista64. My program requires QueryFullProcessImageName() to work on Vista but not on XP. I try to load QueryFullProcessImageName() (instead of linking statically) via the kernel32.dll so that the same executable can run on both WinXP and Vista. The code that loads it is: //only ...

Is boost shared_ptr<XX> thread-safe?

Is the following code thread safe when using boost shared_ptr. Thanks! class CResource { xxxxxx } class CResourceBase { CResourceBase() { m_pMutex = new CMutex; } ~CResourceBase() { ASSERT(m_pMutex != NULL); delete m_pMutex; m_pMutex = NULL; } private: CMutex *m_pMutex; public: void SetResource(shared_ptr<CResource> res) { CS...

Overloading C++ STL methods

How can I overload the STL implementation for methods like find, erase and insert to take varying parameters? I tried to look up the overloading of STL methods but couldn't find any help. ...

Best logging framework for native C++?

I'm looking for logging framework for C++ project. My best shoot was log4cxx, but it seems that it's abandoned project, with development stopped ~4 years ago, with only one update in last 4-5 years. Anything better that log4cxx? (log4c & log4cpp are also totally out-of-date)... ...

How to put different template types into one vector

Hi, I'd like to construct a message with unknown length or number of arguments. I took a simple template like template <typename T> class Argument { public: int size; int type; T data; }; and with some overloaded addMessage (int value) { Argument<int> *a = new Argument<int>; vec.push_back(a); } (same for string and so ...