c++

How do you integrate a TDD approach with VisualStudio?

I am interested in hearing about experiences using TDD and unit testing for C++ in general with Visual Studio 2005 (Professional) First some background. We have a fairly large project and much of it has been developed on Linux using CppUnit for the unit tests. The project is divided into several libraries, each with their own set of tes...

Is it a problem if multiple different accepting sockets use the same OpenSSL context?

Is it OK if the same OpenSSL context is used by several different accepting sockets? In particular I'm using the same boost::asio::ssl::context with 2 different listening sockets. ...

Strange call stack, could it be problem in asio's usage of openssl?

I have this strange call stack and I am stumped to understand why. It seems to me that asio calls open ssl's read and then gets a negative return value (-37) . Asio seems to then try to use it inside the memcpy function. The function that causes this call stack is used hunderds of thousands of times without this error. It happens ...

Which gcc switch disables "left-hand operand of comma has no effect" warning?

It's a part of larger code base, which forces -Werror on gcc. This warning is generated in a third party code that shouldn't be changed (and I actually know how to fix it), but I can disable specific warnings. This time man gcc failed me, so please, let some gcc master enlighten me. TIA. ...

Why is it wrong to use std::auto_ptr<> with STL containers?

Why is it wrong to use std::auto_ptr<> with STL containers? ...

Using the Window API, how do I ensure controls retain a native appearance?

Some of the controls I've created seem to default to the old Windows 95 theme, how do I prevent this? Here's an example of a button that does not retain the Operating System's native appearance (I'm using Vista as my development environment): HWND button = CreateWindowEx(NULL, L"BUTTON", L"OK", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, ...

Learning C, C++ or Delphi ?

I have been developing for about 8 years, and mainly come from a Web Background. I have extensively used the .Net Framework for development the last 5 odd years, including Web, Windows and Mobile. I have a good understanding of C# and VB, VB.Net I am thinking of learning a new language, and based on the interest I have understanding how...

Is this C++ structure initialization trick safe?

Instead of having to remember to initialize a simple 'C' structure, I might derive from it and zero it in the constructor like this: struct MY_STRUCT { int n1; int n2; }; class CMyStruct : public MY_STRUCT { public: CMyStruct() { memset(this, 0, sizeof(MY_STRUCT)); } }; This trick is often used to initiali...

Best introduction to C++ template metaprogramming?

Static metaprogramming (aka "template metaprogramming") is a great C++ technique that allows the execution of programs at compile-time. A light bulb went off in my head as soon as I read this canonical metaprogramming example: #include <iostream> using namespace std; template< int n > struct factorial { enum { ret = factorial< n - 1 >...

Should I use #define, enum or const?

In a C++ project I'm working on I have a flag kind of value which can have 4 values. Those 4 flags can be combined. Flags describe the records in database and can be: new record deleted record modified record existing record Now, for each Record I wish to keep this attribute, so I could use enum: enum { xNew, xDeleted, xModified, xE...

Are C++ non-type parameters to (function) templates ordered?

I am hosting SpiderMonkey in a current project and would like to have template functions generate some of the simple property get/set methods, eg: template <typename TClassImpl, int32 TClassImpl::*mem> JSBool JS_DLL_CALLBACK WriteProp(JSContext* cx, JSObject* obj, jsval id, jsval* vp) { if (TClassImpl* pImpl = (TClassImpl*)::JS_GetInst...

What are the advantages of using Objective-C over C++

I have heard mention of Objective-C but I have never used it myself. I was curious what everyones opinion of it was in general and also in relation to C++. Are there any types of projects where it would be more useful or less useful? ...

How does boost bind work behind the scenes in general?

Without spending a long time reviewing the boost source code, could someone give me a quick rundown of how boost bind is implemented? ...

How to get a stack trace when C++ program crashes? (using msvc8/2005)

Sometimes my c++ program crashes in debug mode, and what I got is a message box saying that an assertion failed in some of the internal memory management routines (accessing unallocated memory etc.). But I don't know where that was called from, because I didn't get any stack trace. How do I get a stack trace or at least see where it fail...

How do you determine the size of a file (in C) for files that are larger than 4GB?

The code currently does this and the fgetpos does handle files larger than 4GB but the seek returns an error, so any idea how to seek to the end of a file >4GB? fpos_t currentpos; sok=fseek(fp,0,SEEK_END); assert(sok==0,"Seek error!"); fgetpos(fp,&currentpos); m_filesize=currentpos; ...

Accessing files across the windows network with near MAX_PATH length

I'm using C++ and accessing a UNC path across the network. This path is slightly greater than MAX_PATH. So I cannot obtain a file handle. But if I run the program on the computer in question, the path is not greater than MAX_PATH. So I can get a file handle. If I rename the file to have less characters (minus length of computer name)...

How to use one object's method to update another object's attribute?

I have three (C++) classes: Player, Hand, and Card. Player has a member, hand, that holds a Hand. It also has a method, getHand(), that returns the contents of hand. Hand Player::getHand() { return hand; } Hand has a method, addCard(Card c), that adds a card to the hand. I want to do this: player1.getHand().addCard(c); but it ...

What is the cost of using a pointer to member function vs. a switch?

I have the following situation: class A { public: A(int whichFoo); int foo1(); int foo2(); int foo3(); int callFoo(); // cals one of the foo's depending on the value of whichFoo }; In my current implementation I save the value of whichFoo in a data member in the constructor and use a switch in callFoo() to decide ...

Understanding C++ boost library the easy way

I have been using C++ boost library for about 2 years now. However, I haven't found any good documentation that gives an overview of how its various components have been implemented and the involved basic principles for implementation. I am aware of the following resources, that cover bits and parts of boost. 1) Boost documentation - ...

Multiple services from the same executable

Hello all, I've written a small service (plain Win32) and I'd like to know if it's possible to run multiple instances of it when multiple users are logged on. Basically, let's say we've got UserA and UserB for UserA the service would log on as "domain\UserA" and for UserB the service would log on as "domain\UserB" - this is from the sa...