Template Problem

  • Thread starter Thread starter Jens Mander
  • Start date Start date
J

Jens Mander

The following code generates errors when compiled using VC++ 7.1. However,
gcc 3.2.2 and comeau online have no problems with it. Is this illegal code
or a compiler bug? If it is the latter; was it fixed in the latest release
of VC++? Are there any workarounds for my version?

Thank you in advance!

====================
template <typename T>
struct Outer
{
template <T value = 0>
struct Inner {};
};

int main ()
{
Outer<int>::Inner<> fail;
}
====================
cl test.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

test.cpp
test.cpp(10) : error C2976: 'Outer<T>::Inner' : too few template arguments
with
[
T=int
]
test.cpp(5) : see declaration of 'Outer<T>::Inner'
with
[
T=int
]
test.cpp(10) : error C2955: 'Outer<T>::Inner' : use of class template
requires t
emplate argument list
with
[
T=int
]
test.cpp(5) : see declaration of 'Outer<T>::Inner'
with
[
T=int
]
test.cpp(10) : error C2955: 'Outer<T>::Inner' : use of class template
requires t
emplate argument list
with
[
T=int
]
test.cpp(5) : see declaration of 'Outer<T>::Inner'
with
[
T=int
]
test.cpp(10) : error C2133: 'fail' : unknown size
test.cpp(10) : error C2512: 'Outer<T>::Inner' : no appropriate default
construct
or available
with
[
T=int
]
test.cpp(10) : error C2262: 'fail' : cannot be destroyed
 
Hello Jens,

I do not claim to know a log about templates but the following code will
compile in VS2005. It is slightly different from your code where the inner
template definition omits 'value = 0'. Can you explain how you intend to
use the template argument T in 'Inner'?

template <typename T>
struct Outer
{
template<typename T>
struct Inner {};
};

int main()
{
Outer<int>::Inner<int> fail;
return 0;
}
 
Back
Top