c++

C++ template destructors for both primitive and complex data types

In a related question I asked about creating a generic container. Using polymorphic templates seems like the right way to go. However, I can't for the life of me figure out how a destructor should be written. I want the owner of the memory allocated to be the containers even if the example constructor takes in an array of T (along with ...

Decent profiler for Windows?

Does windows have any decent sampling (eg. non-instrumenting) profilers available? Preferably something akin to Shark on MacOS, although i am willing to accept that i am going to have to pay for such a profiler on windows. I've tried the profiler in VS Team Suite and was not overly impressed, and was wondering if there were any other g...

Why do thread functions need to be declared as '__cdecl'?

Sample code that shows how to create threads using MFC declares the thread function as both static and __cdecl. Why is the latter required? Boost threads don't bother with this convention, so is it just an anachronism? For example (MFC): static __cdecl UINT MyFunc(LPVOID pParam) { ... } CWinThread* pThread = AfxBeginThread(MyFunc, ....

Best open XML parser for C++

Looking for a simple, clean, correct XML parser to use in my C++ project. Read and write my own..extension? You know what I mean. Thanks ...

Making a Nonblocking socket for WinSocks and *nix

In C/C++, how would I turn a blocking socket into a non blocking socket in both WinSocks and *nix; so that select() would work correctly. You can use the pre-processor for the platform specific code. ...

How to get the charset from an HTML page

Hi all, I'm trying to get the charset attribute in any HTML meta tag. (ie.< meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >) Is there any way to do that in C++ under linux. I was using HTML tidy as a parser but I can't get that attribute to return me anything different from us-ascii (even if the encoding is utf-8...

Learning C and/or C++ from beginner to advanced

Hello, I've taken a few courses on C, C++ and data structures back a few years ago but never got to use that knowledge. Nothing advanced, just simple programming concepts that you'd learn in an introductory class. Now I've transferred into a Computer Science major as junior, and all of a sudden realized that I'll need that knowledge, a...

How to block running two instances of the same program?

I need to make sure that user can run only one instance of my program at a time. Which means, that I have to check programatically, whether the same program is already running, and quit in such case. The first thing that came to my mind was to create a file somewhere, when the program starts. Then, each other instance of the program wou...

Portability of #warning preprocessor directive

I know that the #warning directive is not standard C/C++, but several compilers support it, including gcc/g++. But for those that don't support it, will they silently ignore it or will it result in a compile failure? In other words, can I safely use it in my project without breaking the build for compilers that don't support it? ...

C++ Strategy Design Pattern, making an interface array

After having implemented the strategy pattern, I wanted to make an array of the interface-type, to which I can then add any concrete type. For those who don't know the strategy pattern: http://en.wikipedia.org/wiki/Strategy_pattern In this particular example I would want to make a StrategyInterface array, which I can then fill with con...

Visitor Pattern + Open/Closed Principle

Is it possible to implement the Visitor Pattern respecting the Open/Closed Principle, but still be able to add new visitable classes? The Open/Closed Principle states that "software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification". struct ConcreteVisitable1; struct ConcreteVisitabl...

Where can I learn about the C++ Standard Template Library (STL)?

This question is a lot like Good book for learning the C++ standard template library? but aimed at the cash-strapped student type. I remember searching for some reference material about the STL a while back, but I couldn't find any good links. Are there any worthwile free tutorials / references / best-practises available? ...

VC9 and VC8 lib compatibility

(The original question was asked there : http://www.ogre3d.org/phpBB2/viewtopic.php?t=44832 ) Someone asked : "While I would like to build everything in vs2008 (VC9), the PhysX SDK is built with vs2005 (VC8). Would this cause any problems, using all vc9 compiled libs and used in combination with this vc8 lib?" I answered that the day ...

Namespaces and Operator Overloading in C++

When authoring a library in a particular namespace, it's often convenient to provide overloaded operators for the classes in that namespace. It seems (at least with g++) that the overloaded operators can be implemented either in the library's namespace: namespace Lib { class A { }; A operator+(const A&, const A&); } // namespace Lib ...

State of "memset" functionality in C++ with modern compilers

Context: A while ago, I stumbled upon this 2001 DDJ article by Alexandrescu: http://www.ddj.com/cpp/184403799 It's about comparing various ways to initialized a buffer to some value. Like what "memset" does for single-byte values. He compared various implementations (memcpy, explicit "for" loop, duff's device) and did not really find ...

good resource for socket errors?

Where can I find a list of all types of bsd style socket errors? ...

C++ include and import difference

What is the difference between include and import in C++? ...

Design Tab Control with Visual Studio 2008 (without SP1)

Is there any way (maybe directly editing resource files) to configure a Tab Control (add/remove tabs and their captions and contents) at design time with Visual Studio 2008 without SP1 (I heard that SP1 has such feature)? P.S.: I use c++ with wtl ...

MVC Frameworks for Windows Mobile Native Code

Are there any good MVC frameworks for native Windows Mobile code? Barring that could someone link to an open source Windows Mobile or CE project that uses the MVC pattern? ...

How do you specify that an exception should be expected using Boost.Test?

I have a Boost unit test case which causes the object under test to throw an exception (that's the test, to cause an exception). How do I specify in the test to expect that particular exception. I can specify that the test should have a certain number of failures by using BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES but that seems rather unsp...