Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6617899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:45:34+00:00 2026-05-25T20:45:34+00:00

I am trying to create a 2d array class based on boost::multi_array . I

  • 0

I am trying to create a 2d array class based on boost::multi_array. I face two issues in the code given below. (1) The code for the member function col() does not compile saying that ::type’ has not been declared. Where am I going wrong? (2) Is it possible to define the member function data() outside the class? My attempt gives compile error as the typedefs are not available. But I am unable to define the typedefs outside the class because the typedefs in turn require the type T which is available only inside the template class. Thanks.

#include <boost/multi_array.hpp>
#include <algorithm>

template <class T>
class Array2d{
public:
    typedef typename boost::multi_array<T,2> array_type;
    typedef typename array_type::element element;
    typedef boost::multi_array_types::index_range range;

    //is it possible to define this function outside the class?
    Array2d(uint rows, uint cols);
    element * data(){return array.data();}

    //this function does not compile
    template<class Itr>
    void col(int x, Itr itr){
        //copies column x to the given container - the line below DOES NOT COMPILE
         array_type::array_view<1>::type myview  = array[boost::indices[range()][x]];
         std::copy(myview.begin(),myview.end(),itr);
    }

private:
    array_type array;

    uint rows;
    uint cols;
};

template <class T>
Array2d<T>::Array2d(uint _rows, uint _cols):rows(_rows),cols(_cols){
    array.resize(boost::extents[rows][cols]);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:45:35+00:00Added an answer on May 25, 2026 at 8:45 pm
    array_type::array_view<1>::type
    

    You need template and typename here 🙂

    typename array_type::template array_view<1>::type
    ^^^^^^^^             ^^^^^^^^
    

    The keyword template is required because otherwise the < and > will be treated as less and greater because the array_type is a dependent name, and therefore whether array_view is a nested template or not is not known until instantiation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a Quicksort base class using VB.NET, taking it an array
I am trying to create an array of class objects taking an integer argument.
I was trying to create an extension that could slice any array-like class (since
I have a problem. I'm trying to create an array of different class objects
I'm trying to create and zero an array of int s based on a
So basically I am trying to create instances of the class below every time
What i'm trying to do is create a template array class that will store
I am trying to create a class which has a private member that is
I'm trying to create a class that can instantiate arrays at runtime by giving
Im trying to create an array of tm* structs, and then return them at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.