c++

getting rat out of a maze

A rat is placed in a maze at some unknown position in the maze. All we can go is in up, down, right or left directions. And we have two methods: tryMove(<direction>) which returns false if there is a wall and true if we can move. bool hasLadder(): which returns true if there is a ladder to escape. We have to write a function explo...

Declaring a const BYTE * in c++

I am currently trying to make a call to this function call. Here's the declaration: const void* WINAPI CertCreateContext( __in DWORD dwContextType, __in DWORD dwEncodingType, __in const BYTE *pbEncoded, __in DWORD cbEncoded, __in DWORD dwFlags, __in_opt PCERT_CREATE_CONTEXT_PARA pCreatePara ); As ...

How to remove scrollbars in console windows C++

I have been checking out some Rogue like games (Larn, Rogue, etc) that are written in C and C++, and I have noticed that they do not have the scrollbars to the right of the console window. How can I accomplish this same feature? ...

eclipse helios fails to find g++, gdb, $PATH, make

I am using eclipse CDT but it fails to find any of the linux toolchain like make, g++, gdb. seems like it is failing to retrieve $PATH.Could you let me know how can I fix this? ...

How to strip HTML from a text property of a Qt4 widget?

What's the easiest way in terms of coding effort, to change a text property of a Qt4 widget, e.g. QLabel.text, so all HTML tags are removed? The HTML is simple, typically just one to three tags like or and their closing partners. ...

Adding class functionality via composition

Hello, Suppose we have an abstract class Element from which classes Triangle and Quadrilateral are derived from. Suppose yet that these classes are used in conjunction with interpolation methods that depend on the shape of the element. So, basically we create an abstract class InterpolationElement from which we derive InterpolationTri...

Private class functions vs Functions in unnamed namespace

I've found myself that I tend not to have private class functions. If possible, all candidates to private class function rather I put in to unnamed namespace and pass all necessary information as function parameters. I don't have a sound explanation why I'm doing that but at least it looks more naturally to me. As a consequence I need to...

Replacing libstdc++.dylib (4.0) global new and delete operators on OSX

I'm trying hard to replace the global new and delete operators with XCode 3.2, GCC 4.2, libstdc++ 4.0, dynamic version. I took the protypes directly from the header "new" and implemented them. They are pasted below. The project is a .plugin so a dynamic lib. This plug-in MUST delegate allocation to the main application's own alloc/fre...

Why does libxml2 output "text" on an element name (when it's not "text")?

I am use libxml2 for XML parsing. The sample code on the libxml website are hard to follow and seem to lack some details. I arrived at the following code by Googling so I don't even think it's the proper way to do it, but it worked in the sample learning program I wrote, but not this one. I still don't know the proper way to use libxml i...

How to detect header changes in make dependency list

After almost a decade of C# and VC++ coding, I am getting back to a linux – g++ - make – emacs environment. Trying to refresh my memory about writing a make file I did not have many problems, but I stumbled in the following issue, that I admit I do not remember how I solved it in the past: Let’s say that a particular .cpp file have ...

Use template template class argument as parameter

Modern C++ Design gives the following example: template <class T> struct EnsureNotNull { static void Check(T*& ptr) { if (!ptr) ptr = GetDefaultValue(); } }; template < class T, template <class> class CheckingPolicy = EnsureNotNull, template <class> class ThreadingModel > class SmartPtr : public CheckingPol...

Indirectly destroying object from it's own virtual method. Is it a defined behavior?

Am I allowed to indirectly destroy object from within object's own virtual method? Is it a "defined behavior" (as long as I'm not trying to access anything after destroying the object)? Example: #include <memory> #include <stdio.h> using std::tr1::shared_ptr; struct Child{ virtual void selfdestruct() = 0; virtual ~Child(){ ...

what C++ map mean?

I have the following C++ map example code: map<string,string> &weight2price .... weight = ... price = ... if(weight2price.find(weight) == weight2price.end()) weight2price[weight] = price; could anyone tell me what it means by if(weight2price.find(weight) == weight2price.end()) ...

Debugging multithreaded code with gdb but no access to private variables?

Hey guys. My program uses OpenMP at a few parts to do multithreading. It works for the most part, but occasionally stalls and just sits there. So I run it in the debugger, and I find the area it is stalling at. Then I try to examine the current variables, and I get this: 169 if(0<=myPtr[3] && myPtr[3]<=1){//Reassign the velocities....

Finding the memory address of a loaded DLL in a process in C++

I've got a running process which is using 'Test.dll'. I would like to know the exact memory location of the start of Test.dll in memory, but can't seem to be able to. My main problem is that I need to write to an offset from this DLL, but I can't exactly type in Test.dll+some offset when I use Read/WriteProcessMemory. Any help would be...

Windows 7, virtualprotect -> PAGE_EXECUTE_READWRITE

Hello everyone, I just rediscovered an old program which I originally wrote for windows XP. What it should do is change the permissions of a dll already loaded in the process memory. But with win7 the virtualprotect call fails with error 487 (Attempt to access invalid address). The function call looks like this: VirtualProtect((void*)h...

Can I use a SFINAE test in a control flow statement?

I have an SFINAE test for checking if an class has a function. The test works correctly, but I get compiler errors when I try to use it in an if statement. //SFINAE test for setInstanceKey() template <typename K> class HasSetInstanceKey { template <typename C> static char test( typeof(&C::setInstanceKey) ); template <typen...

How do I get the content with libxml2?

I'm using libxml2 and C++. The following function crashes here at return (char*)cur->content;. When I change it to return (char*)cur->name; then it will return attribute which is the name of the tag. What I want is 1, 2, and 3 (based on the XML file below the C++ code). What am I doing wrong? char* xml2sdf::getId(xmlNode* part){ xm...

WZCQueryInterface(NULL, INTF_ALL, &intfEntry_, &dwOidFlags); returning 2

I've got some code that used to get the interface, now it fails all the time. The dwStatus value is getting set to 2. if (DeviceIoControl( ndisUio_, IOCTL_NDISUIO_QUERY_BINDING, pQueryBinding, sizeof(NDISUIO_QUERY_BINDING), Buf, dwBufLength, &dwBytesWritten, ...

How to Detect Screen Orientation Change Event in Windows Mobile 5 & 6 App, With Embedded C++?

Hello, I am in way over my head, and am hoping anyone here can help. I am working with an application that is running on Windows Mobile OS, version 5 and/or 6, which is written in Embedded C++. The problem is that controls in the app get all messed up and moved around when the user does something to switch the display orientation, such...