c++

COM Object Clean Up

What is the difference between the two lines of code below: CComPtr< IInterface > m_interface; IInterface* m_interface; I know that CComPtr help eliminate memory leaks, but I am getting inconsistent results. When declaring the pointer with CComPtr< IInterface > m_interface; and using the interface in my C# code there are no errors, h...

Where is a file mounted?

Given a path to a file or directory, how can I determine the mount point for that file? For example, if /tmp is mounted as a tmpfs filesystem then given the file name /tmp/foo/bar I want to know that it's stored on a tmpfs rooted at /tmp. This will be in C++ and I'd like to avoid invoking external commands via system(). The code should ...

Does ANSI C support ‘templates?’

I’m taking a C++ class, and my teacher mentioned in passing that the typename keyword existed in C++ (as opposed to using the class keyword in a template declaration), for backwards compatibility with “C templates.” This blew my mind. I’ve never seen or heard tell of anything like C++’s templates (except, perhaps, the preprocessor… and ...

return value of operator overloading in C++

Hi I have a question about the return value of operator overloading in C++. Generally, I found two cases, one is return-by-value, and one is return-by-reference. So what's the underneath rule of that? Especially at the case when you can use the operator continuously, such as cout<<x<<y. For example, when implementing a + operation "str...

Is it ok to use a static variable to initalize/register variables?

Language: C++ Toolkit: Qt4 The toolkit I'm using has a static method called int QEvent::registerEventType() to register my own event types. When I subclass this QEvent I need to supply the base class this value. QEvent::QEvent(int type). Is it ok to use a static variable to call this before application starts? Consider the following: ...

TXT messaging or Email Autoresponder with dynamic or queryable response-?? Rails, .NET, Java, C++??

Hey guys, I wanted to write something that could receive text messages and respond with data queried information from my database. I have been playing around with this and discovered that you can send/receive text messages to email addresses. What would I need to write to have the a program to constantly check for new messages to an ...

When should you use the "this" keyword in C++?

Possible Duplicates: Using this in front of member variables in C++ Is excessive use of this in C++ a code smell Years ago, I got in the habit of using this-> when accessing member variables. I knew it wasn't strictly necessary, but I thought it was more clear. Then, at some point, I started to prefer a more minimalistic st...

Best practices with object manager

I'm kinda new to c++ programming and I'm coding an object manager to a multiplayer game but I'm having some doubts about how to manage the client objects. The client object is composed of connected client parameters (like IP, connected time, received data etc). In order to avoid memory fragmentation, I'm planning to allocate a object po...

Why can't I run AssaultCube built from source?

Hi, a error with open source. I have been playing AssaultCube for about 2 weeks and I found that it is open source. I downloaded from SourceForge and I got everything to compile but... It could not find 3 .DLL(libvorbisfile.dll, libogg.dll, libvorbis.dll) files so I downloaded them and put them in \windows\. Now i get the error "the pro...

Best tools for analyzing dll loads conditions in Visual Studio for C++

I am using Visual Studio 2008 to run an application, which loads a number of DLL's at startup, that immediately exits with "The program '[3668] cb_tcl.exe: Native' has exited with code -1072365566 (0xc0150002)." Unfortunately I get no other clues about the source of the problem and the exit occurs before the program starts, but I suspec...

Help with a dynamic-programming problem

The problem is this: There is an array of M binary numbers and each of them is in state '0' or '1'. You can perform several steps in changing the state of the numbers and in each step you are allowed to change the state of exactly N sequential numbers. Given the numbers M, N and the array with the members of course, you are about to calc...

Inheriting off of a list of templated classes, when supplied with the list of template arguments

I'm trying to write some metaprogramming code such that: Inheriting from some class foo<c1, c2, c3, ...> results in inheritance from key<c1>, key<c2>, key<c3>, ... The simplest approach doesn't quite work because you can't inherit from the same empty class more than once. Handling the "..." portion isn't pretty (since it's copy-pasta),...

C++ using 'this' as a parameter

I have a class which looks approximately like this: class MeshClass { public: Anchor getAnchorPoint(x, y) { return Anchor( this, x, y ); } private: points[x*y]; } I want to make another class which represents an "Anchor" point which can get access to the Mesh and modify the point, like this: class Anchor { publi...

Is it possible to have a common pointer between 2 different programs on the same computer

I need 2 different programs to work on a single set of data. I have can set up a network (UDP) connection between them but I want to avoid the transfer of the whole data by any means. It sounds a little absurd but is it possible to share some kind of pointer between these two programs so that when one updates it the other can simple get...

What use is there for 'ends' these days?

I came across a subtle bug a couple of days ago where the code looked something like this: ostringstream ss; int anInt( 7 ); ss << anInt << "HABITS"; ss << ends; string theWholeLot = ss.str(); The problem was that the ends was sticking a '\0' into the ostringstream so theWholeLot actually looked like "7HABITS\0" (i.e. a null at the e...

faster implementation of sum ( for Codility test )

How can the following simple implementation of sum be faster? private long sum( int [] a, int begin, int end ) { if( a == null ) { return 0; } long r = 0; for( int i = begin ; i < end ; i++ ) { r+= a[i]; } return r; } EDIT Background is in order. Reading latest entry on coding horror, I cam...

Getting ptr from memory address with c++

Im trying to get the engine version of a game from a global pointer, but I am fairly new to this. Here is a very small example I found... http://ampaste.net/mb42243 And this is the disassembly for what I am trying to get, the pointer (gpszVersionString) is the highlighted line (line 5) http://ampaste.net/m2a8f8887 So what I need to f...

confusing use of a comma in if statement

I have this piece of code in c++ ihi = y[0]>y[1] ? (inhi=1,0) : (inhi=0,1); But how would it look in C#? Many thanks, ...

Skip compile-time symbol resolution when building Linux shared libraries with dependencies

Is there a gcc flag to skip resolution of symbols by the compile-time linker when building a shared library (that depends on other shared libraries)? For some reason my toolchain is giving undefined reference errors when I try to build shared library C that depends on B.so and A.so, even though the dependencies are specified and exist. I...

how to specify Qt plugin constructor?

I wonder if it is possible to specify a constructor in a Qt plugin interface? (extending an app) I want to force the plugins using the interface to take a parameter in the constructor. ...