c++

C++ string diff (a la Python's difflib)

I'm trying to diff two strings to determine whether or not they solely vary in one numerical subset of the string structure; for example, varies_in_single_number_field('foo7bar', 'foo123bar') # Returns True, because 7 != 123, and there's only one varying # number region between the two strings. In Python I can use the difflib to accom...

string to char* marshaling

Hi, a strange problem .... I wrote a managed c++ class that has the followig function: void EndPointsMappingWrapper::GetLastError(char* strErrorMessage) { strErrorMessage = (char*) Marshal::StringToHGlobalAnsi(_managedObject->GetLastError()).ToPointer(); } As you can see, this is simple methode to copy the managed string of the l...

Help getting QTP to identify a control

We're trying to use QTP (QuickTest Professional) to auto-test a legacy C++ application. However, the main window for the app is composed of several IDENTICAL panels. Each panel has a unique title. If I view the window in Spy++ (comes with DevStudio), I see: + Window <hwnd> "Window Title" taskwindowclass + Window <hwnd> "Panel A" ch...

Replacing auto_ptr in VC++ 8

std::auto_ptr is broken in VC++ 8 (which is what we use at work). My main gripe with it is that it allows auto_ptr<T> x = new T();, which of course leads to horrible crashes, while being simple to do by mistake. From an answer to another question here on stackoverflow: Note that the implementation of std::auto_ptr in Visual Studio 2...

Is it better in C++ to pass by value or pass by constant reference?

Is it better in C++ to pass by value or pass by constant reference? I am wondering which is better practice. I realize that pass by constant reference should provide for better performance in the program because you are not making a copy of the variable. ...

Is it possible to program iPhone in C++

I'm all for language diversity, but Objective C is insane. So I'm curious: is it possible to code iPhone apps with C++ while using the Cocoa API, etc? ...

is assert(false) ignored in release mode (VC++)?

Is assert(false) ignored in release mode (VC++)? ...

Does anyone know of a good, simple C++ based SIP stack that I could use?

I'm looking for a very simple way of answering a call placed down a SIP trunk. I don't need anything more than being able to answer the call when it rings and being able to detect when it has ended. Does anyone have any good pointers to get me started? Ideally, I'd like to find some simple open-source C++ code that I could use as a ba...

ASSERT vs. ATLASSERT vs. assert

I am refactoring some MFC code that is littered with ASSERT statements, and in preparation for a future Linux port I want to replace them with the standard assert. Are there any significant differences between the two implementations that people know of that could bite me on the backside? Similarly, I have also come across some code th...

Testing for assert in the Boost Test framework

I use the Boost Test framework to unit test my C++ code and wondered if it is possible to test if a function will assert? Yes, sounds a bit strange but bear with me! Many of my functions check the input parameters upon entry, asserting if they are invalid, and it would be useful to test for this. For example: void MyFunction(int para...

If abstract base C++ class is actually an interface, so it own no data members, is it obligatory to call base class constructor in derived class constructor?

I have a code: class AbstractQuery { virtual bool isCanBeExecuted()=0; public: AbstractQuery() {} virtual bool Execute()=0; }; class DropTableQuery: public AbstractQuery { vector< std::pair< string, string> > QueryContent; QueryValidate qv; public: explicit DropTableQuery(const string& qr): AbstractQuery(), qv(q...

How to build an ActiveX object in C++ that can be scripted using Javascript

I can use VS08's MFC/ActiveX template to create a C++ ActiveX object that I can load into a HTML page and script with Javascript. But I can't figure out how to create an interface that allows me to call custom methods on my component with Javascript. Could you please tell me how to accomplish that? I have spent over two hours on google ...

Using Lists in C#

I am an upper level Software Engineering student currently in a Data Structures and Algorithms class. Our professor wants us to write a program using the List structure found in the C++ STL. I have been trying to use C# more and more, and was wondering if the ArrayList structure in .NET is a good substitute for the STL List implementat...

Why should I declare a virtual destructor for an abstract class in C++?

I know it is a good practice to declare virtual destructors for base classes in C++, but is it always important to declare virtual destructors even for abstract classes that function as interfaces? Please provide some reasons and examples why. ...

Can any one provide me a sample of Singleton in c++?

I write a singleton c++ in the follow way: class A { private: static A* m_pA; A(); virtual ~A(); public: static A* GetInstance(); static void FreeInstance(); void WORK1(); void WORK2(); void WORK3(); } } A* A::GetInstance() { if (m_pA == NULL) m_p...

g++ partial linking instead of archives?

I'm pretty new to the C++ build flow, and I'm thinking of switching to use partial linking for my libraries instead of creating ar archives. I'm hoping to reduce link time in an inevitable final compilation step that I have, and I figure partial linking some libraries once could save me time over linking everything in that final step. I...

invoking functions while debugging with Visual Studio 2005?

Here's something I know is probably possible but I've never managed to do In VS2005(C++), While debugging, to be able to invoke a function from the code which I'm debugging. This feature is sometimes essential when debugging complex data structures which can't be explored easily using just the normal capabilities of the watch window. The...

What is the difference between an int and a long in C++?

Correct me if I am wrong, int is 4 bytes, with a range of values from -2,147,483,648 to 2,147,483,647 (2^31) long is 4 bytes, with a range of values from -2,147,483,648 to 2,147,483,647 (2^31) What is the difference in C++? Can they be used interchangeably? ...

How to statically link an existing linux executable?

Looking for a way to convert a dynamically linked executable to a static executable. Seems like it should be possible but man pages are turning up short and google's not helping either. ...

What do you think is making this C++ code slow? (It loops through an ADODB recordset, converts COM types to strings, and fills an ostringstream)

This loop is slower than I would expect, and I'm not sure where yet. See anything? I'm reading an Accces DB, using client-side cursors. When I have 127,000 rows with 20 columns, this loop takes about 10 seconds. The 20 columns are string, int, and date types. All the types get converted to ANSI strings before they are put into th...