In preparing to a OOP exam, I enjoyed seeing g++ compile the following code (without an instantiation) even though it appeared to make no sense:
template<class T> void f() {
T t = "a";
t += 5.6;
t->b();
T* p = t;
p = p*(t/"string");
}
I then set out on a challenge to make this instantiate and compile.
I created the following class:
class A {
public:
A(const char* s) {}
void operator+=(double d) {}
A operator/(char* str) {return A("");}
A* operator->() {return this;}
A* operator=(A& a) {return &a;}
void b() {}
};
A* operator*(A* a, A b) {return new A("");}
which allowed almost all of the template to work, except the line
T* p = t;
My question is, what operator or constructor will make this line work? Currently it gives me "error: cannot convert ‘A’ to ‘A*’ in initialization"