#include <iostream.h>
#include <conio.h>
As it has been pointed out, iostream.h
and conio.h
are not standard headers for C++ programs. The correct header include statement for the IO streams library is #include <iostream>
, without the extension.
typedef ostream& (*T)(ostream& , int);
This creates a typedef
named T
which is a pointer to a function with these properties:
- returns a reference to
ostream
- accepts two parameters, in this order:
- a reference to an
ostream
int
value
ostream
, assuming it's referring to std::ostream
, is itself a typedef
of std::basic_ostream
, which is found in the C++ standard library. It is defined as:
namespace std {
typedef basic_ostream<char> ostream;
}
Objects std::cout
are instances of std::ostream
.
class Base
{
T fun; // (1)
int var; // (2)
public:
Base(T func, int arg): fun(func) , var(arg) {}; // (3)
friend ostream& operator<<(ostream& o, Base& obj) // (4)
{
return obj.fun(o, obj.var);
}
};
This is a class that holds two things: (1) a pointer to a function as described above and (2) an integer. The constructor (3) allows users of the class to instantiate it with a function pointer and an integer.
The friend function declaration (4) overloads the left bitshift operator <<
. This sort of overloading is called operator overloading. By convention, The operator <<
is also called the stream insertion operator in the context of IO streams.
Note that friend functions defined this way are actually not members of Base
, and thus do not receive a this
pointer (hence, the need for a separate Base&
parameter).
ostream& odisp(ostream& o, int i);
{
o << "i=" << i << endl;
return o;
}
This is a function called odisp
. It takes in a reference to an ostream
and an integer. If you pass in the integer 42, it prints out the passed-in integer in this form:
i=42
Base disp(int i)
{
return base(odisp, i)
};
This function has multiple syntax errors and will not run as-is:
base
is probably meant to be Base
. In this case it would construct a Base
temporary and returns it.
- Missing a semicolon.
These issues are somewhat fundamental to the language. You may want to pick up a good introductory C++ book which will cover these issues.