If I want to use a pointer to a class and I dont do any operations on it, we can forward declare the class. But if that happens to be a typedef, why is it not allowed? In the following example, it compiles only i include the commented code but why does compiler wants to know about it at that point? How do I forward declare something which may be a typedef. Is there any changes in this behavior in c++0x?
#include <iostream>
using namespace std;
/*
template<class T>
class temp;
typedef temp<int> later;
*/
class later;
void somefunc(later*);
int main()
{
later* l;
somefunc(l);
return 0;
}
//The following is in someother file/compilation unit.
template<class T>
struct temp
{
public:
void print()
{
T t(5);
std::cout<< "helloworld: " << t << std::endl;
}
};
typedef temp<int> later;
void somefunc(later* l)
{
l = new later();
l->print();
}