c++

User-defined cast to string in C++ (like __repr__ in Python)

How do I make something like user-defined __repr__ in Python? Let's say I have an object1 of SomeClass, let's say I have a function void function1(std::string). Is there a way to define something (function, method, ...) to make compiler cast class SomeClass to std::string upon call of function1(object1)? (I know that I can use strings...

Why can't you use offsetof on non-POD strucutures in C++?

I was researching how to get the memory offset of a member to a class in C++ and came across this on wikipedia: In C++ code, you can not use offsetof to access members of structures or classes that are not Plain Old Data Structures. I tried it out and it seems to work fine. class Foo { private: int z; int func() {cout << ...

Linking with a debug/release lib with qmake/Qt Creator

I am using Qt Creator and have a Qt GUI project that depends on a C++ static library project. I want to link the release version of the GUI app with the release build of the .lib and the debug release of the GUI app with the debug .lib. I have found out how to add additional libraries to the project by including a line like the followi...

How to identify an Explorer Bar(Internet Explorer) is hidden or not?

I can make an Explorer bar show/hide using IWebBrowser2::ShowBrowserBar Method. I want to use a single button to toggle between Show/Hide. There is a parameter for ShowBrowserBar to set for Show/Hide. How will I get the status of the explore bar now? ...

Checking digital signature programmatically

I have the exe for the project im working on signed by a digital signature which means when it asks for admin rights it shows the company name. This works very well but if you modify the exe it will still work and show unknown there instead. Is there a way to check the digital signature to see if it is valid when you run the exe to avo...

Is it possible to assign object to int?

I have a CCounter class which holds and integer value protected by mutex. I've defined several operators like post/pre inc/dec returning an integer so I can do: CCounter c(10); int i = c++; but what do I do with a simple assignment like i = c ? I tried to define friend operator= but it gives me operator=(int&, const CCounter&)’ must ...

Derived data type

Why is an array called a derived data type? ...

compile cdrtools with mingw

Hello All, I need to compile cdrtools with mingw (to avoid cygwin dependancy). It was done somehow long time ago but sources are not available anymore: http://web.archive.org/web/20040707140819/http://cdrtools.bootcd.ru/ Does anyone know how to compile cdrtools with mingw? Thanks. ...

[msvc,c++] Enable auto-build when F5 is pressed and source is out-of-date

When I press F5 and source was modified, my Visual Studio doesn't rebuild the source and runs the existing (out-of-date) executable. I need to press F7 then F5. How do I tell msvc to auto-rebuild when I press F5? This is MSVC 2005, C++. ...

Can I add breakpoint on CreateProcess in VS

Can I add breakpoint on windows CreateProcess API in Visual studio like I can do in Windbg? ...

Transfer a boost::ptr_list from a library to a client

I dynamically load a library in C++ like described here. My abstract base class looks like this: #include <boost/ptr_container/ptr_list.hpp> class Base { public: virtual void get_list(boost::ptr_list<AnotherObject>& list) const = 0; }; And my library now provides a derived class Derived class Derived : public Base { ... }; void...

Link Checker With ShellExecute?

I've been tasked with going through a database and checking all of the links, on a weekly schedule. I normally work in PHP, but doing this in PHP would be very slow (it actually would timeout the page after about 100 URLs), so I decided to make a quick C++ app. Admitidly, I haven't used C++ since college, so I'm a bit rusty. I found th...

Error while using Boost with Visual Studio 2008

I am using Boost with Visual Studio 2008 and I have put the path to boost directory in configuration for the project in C++/General/"Additional Include Directories" and in Linker/General/"Additional Library Directories". (as it says here: http://www.boost.org/doc/libs/1_36_0/more/getting_started/windows.html#build-from-the-visual-studio-...

How are float and doubles represented in C++ (gcc)?

How are floating points represented and interpreted by a compiler. I am trying to understand that so I can easily interpret what byte array would mean for floats and doubles. Thanks ...

C++, statically detect base classes with differing addresses?

If I have a derived class with multiple bases, each this pointer for each base will be different from that of the derived object's this pointer, except for one. Given two types in an inheritance hierarchy, I'd like to detect at compile time whether they share the same this pointer. Something like this should work, but doesn't: BOOST_STA...

Are there any generic C++ APIs or SDKS for cameras that work on CE and Win32

I have a mobile application with versions run on TabletPCs (Win32) and Rugged PDAs (Windows CE, Windows Mobile 4 & 5). Are there any SDKs out there that I can use that will work with a range of cameras across these operating systems? On Windows CE I can use SHCameraCapture which will work with built in cameras, but typically not with e...

Custom sorting problem, always force 0 to back of ascending order?

Premise This problem has a known solution (shown below actually), I'm just wondering if anyone has a more elegant algorithm or any other ideas/suggestions on how to make this more readable, efficient, or robust. Background I have a list of sports competitions that I need to sort in an array. Due to the nature of this array's populati...

Is there a way to prevent a "keyword" from being syntax highlited in MS Visual Studio

MS Visual Studio editor highlights some non-keyword identifiers as keywords in C++ files. Particularly "event" and "array" are treated as keywords. That's very annoying to me, because they are not C++ keywords. I know how to add my own keywords to the list of syntax-highlighted identifiers, but how to remove existing built-in ones? I'm a...

Why are some operators in C++ only allowed to be overloaded as member functions?

The operators are = () [] -> ->* conversion operators These can be declared only as member functions. Any other operator function can be either a class member or a non-member function. What is the rationale for this restriction? ...

How can I catch an application crash or exit in mshtml?

Our application is using mshtml. That dll is causing our application to exit ungracefully due to well known problems in mshtml since we don't install newer browsers on users' machines. We just use what they have already. The SetUnhandledExceptionFilter() does not handle this, nor does a try/catch block around the calls into mshtml. The...