c++

Wrapping a data structure

I have a data structure that I want to access / modify in different ways in different situations. I came up with this: class DataStructure { public: int getType(); private: // underlying data containers }; class WrapperBase { public: void wrap(DataStructure *input) {dataStructure = inp...

C/C++: Detecting superfluous #includes?

I often find that the headers section of a file get larger and larger all the time but it never gets smaller. Throughout the life of a source file classes may have moved and been refactored and it's very possible that there are quite a few #includes that don't need to be there and anymore. Leaving them there only prolong the compile time...

Why does this code corrupt memory?

This is a fairly newbie question which should be answerable reasonably quickly... Basically, after the first call to Printf in echo, the contents of args is corrupted. It sounds to me like i'm passing the pointers around incorrectly. But can't figure out why? #define MAX_PRINT_OUTPUT 4096 void Echo(char *args[MAX_COMMAND_ARGUMENTS], i...

Caching expensive data in C++ - function-scoped statics vs mutable member variables

Hi, I've got a relatively expensive data-fetching operation that I want to cache the results of. This operation is called from const methods, roughly like this: double AdjustData(double d, int key) const { double factor = LongRunningOperationToFetchFactor(key); return factor * d; } I'd like AdjustData to remain const, but I want ...

How can I make my C++ ActiveX control print nicely in Excel?

I am trying to get my ActiveX control to print out nicely in Excel. The control is written in C++. Originally I generated the control using the Visual Studio 2005 wizard. I have tested this with a simple wizard generated control to experiment with the OnDraw function and I discovered that even a control straight out of the wizard doe...

Should I learn Python after C++?

Hi guys, I`m currently studying C++ and want to learn another language. For work I use C# + ASP (just started learning it, actually), but I want something "less Microsoft" and powerful. I have heard Python is a popular and powerful language, not so complicated as C++. But many people mentioned it was hard for them to get back to C++/Java...

C++ Parallelization Libraries: OpenMP vs. Thread Building Blocks

Hi, I'm going to retrofit my custom graphics engine so that it takes advantage of multicore CPUs. More exactly, I am looking for a library to parallelize loops. It seems to me that both OpenMP and Intel's Thread Building Blocks are very well suited for the job. Also, both are supported by Visual Studio's C++ compiler and most other po...

Is there any reason to check for a NULL pointer before deleting ?

I see some legacy code checking for null before deleting the pointer. as like below if(NULL != pSomeObject)//any reason for checking for null { delete pSomeObject; pSomeObject = NULL;//any reason for assigning null } my compiler is vc6 pre-standard one though. ...

Is it OK to pass parameters to a Factory method?

One of the ways to implement Dependency Injection correctly is to separate object creation from business logic. Typically, this involves using a Factory for object creation. Up until this point, I've never seriously considered using a Factory so I apologize if this question seems a little simplistic: In all the examples of the Factory...

How to get width and height from CreateWindowEx() window? C++

I have made a window with CreateWindowEx() function, now how do i get the width and height from that window i created? This sounds very basic thing to do, but i just couldnt find any answer ;_; This is needed because the window height is created automatically depending on how the Windows wants to create it. Language C or C++ ...

InterlockedIncrement usage

While reading about the function InterlockedIncrement I saw the remark that the variable passed must be aligned on a 32-bit boundary. Normally I have seen the code which uses the InterlockedIncrement like this: class A { public: A(); void f(); private: volatile long m_count; }; A::A() : m_count(0) { } void A::f() { ::Inte...

How to get the running version of Power Point using C++ unmanaged?

Hi Guys, I am using C++ unmanaged with Power Point (2003 and 2007). How do I get the running version of Power Point (2003 or 2007) with IDispatch? Thanks, any help would be awesome. ...

Parsing a string in C++

I have a huge set of log lines and I need to parse each line (so efficiency is very important). Each log line is of the form cust_name time_start time_end (IP or URL )* So ip address, time, time and a possibly empty list of ip addresses or urls separated by semicolons. If there is only ip or url in the last list there is no separato...

How to make a copyable boost::signal?

I get why boost::signal is noncopyable (it's because copying a signal doesn't have a clear meaning), but I need a version of it that does provide some sort of copy ctor (either a no-op or one that copies all connections). The reason I need this is because in my project many objects become noncopyable just by virtue of featuring signals,...

Reasons for stack unwinding fail

I was debugging an application and encountered following code: int Func() { try { CSingleLock aLock(&m_CriticalSection, TRUE); { //user code } } catch(...) { //exception handling } return -1; } m_CriticalSection is CCricialSection. I found that user code throws an exception such that m_CriticalSection is...

C++: Multiple inheritance + virtual function mess

I have a diamond multiple inheritance scenario like this: A / \ B C \ / D The common parent, A, defines a virtual function fn(). Is it possible for both B and C to define fn()? If it is, then the next question is - can D access both B and C's fn() without disambiguation? I'm assuming there is some syntax for this....

Isn't the Factory pattern the same thing as global state?

Let's say I have a class like this: class MonkeyFish { MonkeyFish( GlobalObjectA private: GlobalObjectA GlobalObjectB GlobalObjectC } Without a factory, I need to do the following in order to instantiated a MonkeyFish. GlobalObjectA a; GlobalObjectB b; GlobalObjectC c; int main() { MonkeyFish * monkey_f...

Portable C++ Stack Trace on Exception

I am writing a library that I would like to be portable. Thus, it should not depend on glibc or Microsoft extensions or anything else that is not in the standard. I have a nice hierarchy of classes derived from std::exception that I use to handle errors in logic and input. Knowing that a particular type of exception was thrown at a pa...

How to get Last Active Cell in Excel 2007

I am working with C++ unmanaged and Excel 2007. I am using a call to the Excel4 API to get the range of cells selected by the user. When the user selects what I call a "common" range, this call returns a range like this "R1C1:R4C3", which is exactly the format that I need for doing other operations in my application. However, when the ...

Copy-on-write with shared_ptr when multithreading

In the absence of multithreading, the implementation of copy-on-write for shared_ptr (either from boost or tr1) using unique() is straightforward. Which changes need to be made when multithreading? The reference count is atomic so I assume I can create, copy-construct, read and destroy instances of shared_ptr without further concerns. H...