【发布时间】:2012-02-07 12:09:12
【问题描述】:
以下程序在我看来还不错。但我无法编译它。
#include <iostream>
#include <vector>
using namespace std;
int main()
{
struct a
{
int i;
int j;
};
std::vector<a*> vecA;
a* pA = new a;
pA->i = 4;
pA->j = 9;
vecA.push_back(pA);
return 0;
}
它会产生以下错误。
struct_update.cc: In function ‘int main()’:
struct_update.cc:32:19: error: template argument for ‘template<class _Alloc> class std::allocator’ uses local type ‘main()::a*’
struct_update.cc:32:19: error: trying to instantiate ‘template<class _Alloc> class std::allocator’
struct_update.cc:32:19: error: template argument 2 is invalid
struct_update.cc:32:25: error: invalid type in declaration before ‘;’ token
struct_update.cc:39:10: error: request for member ‘push_back’ in ‘vecA’, which is of non-class type ‘int’
【问题讨论】:
-
对我来说编译得很好...(Visual Studio 2010 SP1)
-
@honk 上面的代码不适用于 g++(最新版本可用于 ubuntu 11.10 至今)
标签: c++ pointers vector struct