Archive for March 30, 2008
Visual C++ Preprocessor null directive
0![]()
Well, add an empty # symbol to your #include list and compile the project. For e.g. see the following #include list.
#include “stdafx.h”
#include “Dialog.h”
#
#include “DialogDlg.h”
It will compile without showing any errors. Weird?
![]()
The single “#” in a line is called null directive. It has no effect. Indeed, its not a bug. ![]()
But i can’t find the answer for question… What is the purpose?
Reduce iostream compilation dependency by using iosfwd
0![]()
For making our classes compatible with cin and cout, we usually over load << and >> operators. And if such classes are the part of our modules interface, the iostream header file should be added to the interface header of our module. It makes compilation overhead for the classes those use our exported class. Please see the following code block.
#include <iostream>
class IMyInterface
{
public:
// Overloaded << operator.
std::ostream& operator<<( std::ostream& os );
};
![]()
You can easily reduce the compile time dependency of iostream header by using iosfwd. It contains forward declaration of several template classes defined in iostream. Please check MSDN for more details. Don’t forget to include iostream in your cpp files, since iosfwd contains just forward declarations.
#include <iosfwd>
class IMyInterface
{
public:
// Overloaded << operator.
std::ostream& operator<<( std::ostream& os );
};