Can you fill in code for the address_of()
function so that the program (1) compiles without warning, and (2) prints the addresses of all four objects correctly?
#include <iostream>
template <class T>
inline T * address_of(T & obj)
{
// Huh?
}
struct foo
{
foo() { }
foo * operator& () { return 0; }
foo const * operator& () const { return 0; }
};
int main(int, char * [])
{
double d1;
double const d2( 0 );
std::cout << address_of(d1) << std::endl;
std::cout << address_of(d2) << std::endl;
foo f1;
foo const f2;
std::cout << address_of(f1) << std::endl;
std::cout << address_of(f2) << std::endl;
return 0;
}