#include <iostream>
#include <vector>
int main()
{
class Int {
public:
Int(int _i) : i(i) {}
private:
int i;
};
std::vector<Int> VI;
}
I try to compile the above code and got the following error message:
foo.cc: In function 'int main()':
foo.cc:13: error: 'main()::Int' uses local type 'main()::Int'
foo.cc:13: error: trying to instantiate 'template<class _Alloc> class std::allocator'
foo.cc:13: error: template argument 2 is invalid
foo.cc:13: error: invalid type in declaration before ';' token
Could anyone of you tell me why I can't do things like this in C++? Thanks in advance.
The standard explictly prohibits using local classes to instantiate templates in 14.3.1[temp.arg.type]/2.
A local type, a type with no linkage, an unnamed type or a type compounded from any of these types shall not be used as a template-argument for a template type-parameter.
This will be changed in C++0x.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With