【发布时间】:2011-06-22 10:09:50
【问题描述】:
如果我想使用一个指向类的指针并且我不对它做任何操作,我们可以转发声明这个类。但是,如果这恰好是 typedef,为什么不允许呢? 在下面的例子中,它只编译了我包含注释的代码,但为什么编译器想知道它呢?我如何转发声明可能是 typedef 的东西。在 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();
}
【问题讨论】:
标签: c++ c++11 typedef forward-declaration