c++ - error C2899: typename cannot be used outside a template declaration -
i trying following in msv2010
namespace statismo { template<> struct representertraits<itk::image<itk::vector<float, 3u>, 3u> > { typedef itk::image<itk::vector<float, 3u>, 3u> vectorimagetype; typedef vectorimagetype::pointer datasetpointertype; typedef vectorimagetype::pointer datasetconstpointertype; typedef typename vectorimagetype::pointtype pointtype; typedef typename vectorimagetype::pixeltype valuetype; }; i getting following error:
error c2899: typename cannot used outside template declaration
an in workaround appreciated.
namespace statismo { template<> struct representertraits<itk::image<itk::vector<float, 3u>, 3u> > { // bla typedef typename vectorimagetype::pointtype pointtype; ^^^^^^^^ typedef typename vectorimagetype::pixeltype valuetype; ^^^^^^^^ }; your typename keywords placed inside explicit specalization of representertraits<t> itk::image<itk::vector<float, 3u>, 3u>. however, regular class, not class template. means vectorimagetype not dependent name , compiler knows pixeltype nested type. that's why it's not allowed use typename. see als this q&a.
note in c++11, restriction has been lifted, , use of typename allowed not required in non-template contexts. see e.g. example
#include <iostream> template<class t> struct v { typedef t type; }; template<class t> struct s { // typename required in c++98/c++11 typedef typename v<t>::type type; }; template<> struct s<int> { // typename not allowed in c++98, allowed in c++11 // accepted g++/clang in c++98 mode (not msvc2010) typedef typename v<int>::type type; }; struct r { // typename not allowed in c++98, allowed in c++11 // accepted g++ in c++98 mode (not clang/msvc2010) typedef typename v<int>::type type; }; int main() { } live example (just play g++/clang , std=c++98 / std=c++11 command line options).
Comments
Post a Comment