|
Boost : |
Subject: Re: [boost] [multi-array] compiler errors with visual studio 2012 (nfarnsworth@web.de)
From: Dan Searles (dansearles_at_[hidden])
Date: 2013-03-27 11:03:50
>Date: Sat, 23 Mar 2013 14:12:24 +0100 (CET)
>From: nfarnsworth_at_[hidden]
>To: boost_at_[hidden]
>Subject: [boost] [multi-array] compiler errors with visual studio 2012
>Message-ID:
> <trinity-07de36eb-bb16-4dc9-b97b-68516d068e24-1364044344811_at_3capp-webde-bs37>
>
>Content-Type: text/plain; charset="UTF-8"
>
>
> Hello,
> have this c++ example which compiles with Visual Studio 2010 but with Visual
> Studio 2012 I got this compiler errors:
> 1>------ Build started: Project: MultiArrayDemo, Configuration: Debug Win32
> ------
> 1> MultiArrayDemo.cpp
> 1>d:\sandbox\multiarraydemo\multiarraydemo\multiarraydemo.cpp(11):error
> C2059: syntax error : '<'
> 1> d:\sandbox\multiarraydemo\multiarraydemo\multiarraydemo.cpp(25)
> : see reference to class template instantiation 'Data<T>' being compiled
> 1>d:\sandbox\multiarraydemo\multiarraydemo\multiarraydemo.cpp(11):error
> C2238: unexpected token(s) preceding ';'
> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
> The example uses the boost 1.53 version. Here is the example code:
> #include "stdafx.h"
> #include <boost/multi_array.hpp>
> const int rows = 3;
> const int cols = 5;
> template<class T> struct Data
> {
> typedef boost::multi_array<T,2> data_type;
> typedef typename data_type::array_view<1>::type view_type; //here is the
> first error
> typedef typename data_type::index_range range;
> Data()
> :A(boost::extents[rows][cols])
> {
> double tmp[] =
> {1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0};
> A.assign(tmp,tmp+ (rows * cols));
> }
> data_type A;
> };
> int _tmain(int argc, _TCHAR* argv[])
> {
>
> Data<double>* data = new Data<double>();
> Data<double>::view_type myView =
> data->A[boost::indices[0][Data<double>::range()]];
> delete data;
> return 0;
> }
> Does anybody know how to solve this problem?
> Best regards and thank you in advance
> Niklas
According to Microsoft, the code is non-conformant. Visual Studio 2010 allowed the
code to be compiled, but 2012 tightened the requirement. See:
http://msdn.microsoft.com/en-us/library/bb531344.aspx
(Second point, "Use the template keyword...", but note that they highlighted the wrong keyword).
The simple fix is to add the keyword 'template':
typedef typename data_type::template array_view<1>::type view_type; //here is the first error
Dan Searles
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk