When should BOOL and bool be used in C++ and why?
I think using bool is cleaner and more portable because it's a built-in type. But BOOL is unavoidable when you interactive with legacy code/C code, or doing inter-op from .NET with C code/Windows API.
So my policy is:
Use bool inside C++.
Use BOOL when talk to outer world, e.g., export ...
Consider the below:
#include <iostream>
public ref class TestClass {
public:
TestClass() { std::cerr << "TestClass()\n"; }
~TestClass() { std::cerr << "~TestClass()\n"; }
};
public ref class TestContainer {
public:
TestContainer() : m_handle(gcnew TestClass) { }
private:
TestClass^ m_handle;
};
void createContainer()...
MyClass GlobalVar;
int main()
{
MyClass VarInMain;
}
...
Suppose I represent an image class as:
template <typename Pixel> class Image { ... };
I would need my own swap function to prevent extra copying of images, so I would need to make it a friend of Image. If inside Image I write:
template <typename T> friend void swap(Image<T>&, Image<T>&);
I get what I want, but it makes all swap fu...
When I write a program about IO completion port in Windows Vista,
the first sample didn't work and the GetQueuedCompletionStatus() can not get
any OVERLAPPED structures.
So I put the OVERLAPPED structure in global scope,and it works amazingly.
Why is that?
CODE1:
int main()
{
OVERLAPPED o;
..
CreateIoCompletionPort(....);...
Hey, I want to know how to connect databases with C++? Any cross-platform solution which supports many databases? I know about SQLAPI++ but its a shareware... so any free one? What solutions do I have if I limit the OSes to Windows only?
Thanks
...
When I run this program
OVERLAPPED o;
int main()
{
..
CreateIoCompletionPort(....);
for (int i = 0; i<10; i++)
{
WriteFile(..,&o);
OVERLAPPED* po;
GetQueuedCompletionStatus(..,&po);
}
}
it seems that the WriteFile didn't return until the writing job is done. At the same time , GetQueuedC...
I have an application that makes use of the Mozilla LDAP library. We're diagnosing a problem involving the LDAP library failing to make a connection to the server. I'm attempting to get additional information from the LDAP library by tossing a debug version of the lib in with the application and enabling debug using ldap_set_opt. Unfortu...
I have a Visual Studio 2008 project with some legacy native C++ DLL projects, and some newer WPF projects that use the DLLs. When I open the WPF xaml windows in the designer, Visual Studio loads up the native DLLs to be able to display the window.
The problem is, is that if I now need to make a change in the legacy DLLs, I need to cl...
EDIT: See my answer below for the hotfix.
ORIGINAL QUESTION:
In setting up for our boat-programming adventure I have to set up source control and fix project files for a team to use them. (the project was previously only being worked on by one person who took shortcuts with setting up the project includes, etc)
I am fixing those SLN...
Hello,
I'm trying to get my project to compile with the common language runtime, and I'm suddenly running into the following linking errors, when I attempt to make a debug build:
==============================================================================
Main.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent ...
Hi,
I'm trying to make a constructor for a graph class that accepts a string as a
parameter and uses it to build the graph.
The string is formatted as follows: |vertex list|Edges list|
e.g. |1,2,3,4,15|(1->2),(3->2),(4->15)|
The idea is that the constructor will take the values from the string and then
know to perform the following a...
My application (the bootstrap application for an installer that I'm working on needs to launch some other applications (my installer and third party installers for my installer's prerequisites) and wait for them to complete. In order to allow the GUI to do screen updates while waiting for an app to complete, I put a message pump in the w...
I have a VS 2008 C++ project, with one very small and simple code file. I need to write an app to generate this file and build the project into a Win32 DLL. I will need to deliver a free compiler etc. with the app to my client, so I can't automate VS to do this.
How would I best go about this?
...
Hi,
I have a text file that I am inputting data in from, but I can't seem to get it right.
Here are two lines from the text file as an example (these aren't real people don't worry):
Michael Davidson 153 Summer Avenue Evanston CO 80303
Ingrid Johnson 2075 Woodland Road Aurora IL 60507
Her...
I have an ActiveX component which contains a control (webbrowser control embedded in composite control dialog pane) for accessing certain URL. The ActiveX component accessing URL can be used in other MFC or VB projects. The usage is to register the ActiveX component (use regsvr32 cmd) and then insert the control in a dialog window by usi...
I am making an application that simulates an ATM (its totally trivial). I was having a little trouble saving my transactions to the hard disk. The two main questions are: A) Should I save it as a DB or a text-file, B) How would I save to disk using either DB or txt format in STL C++ (I don't really want to use a third-party library but I...
So I have this piece of code and out of convenience I want the default parameter for its constructor be of the int kind and 0. (I have more parameters in a class of my project and one of them is optional and I don't want to write the constructor twice because its big)
class mama{
public:
template<typename x> mama(x i=int(0)){}
}...
By "immutable function" or "immutable method", I mean a function whose result will never vary if you give it the same arguments.
I would be interested to know if anyone know of a more generic or less verbose solution when you want to cache the precomputed value(s) of an immutable function.
Let me explain what I mean with a simple examp...
I'm using QGraphics objects to display boxes with arrows between them. I want animation on those arrows/lines that starts at one end and goes to the other.
The animation works great when the start and end locations of the arrow don't change during QTimeLine execution, i.e. I leave the view static.
But since the user can drag the boxes a...