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 8864849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:21:24+00:00 2026-06-14T16:21:24+00:00

It seems that boost::multi_array<T, n> requires that T have a no-argument constructor. Consider the

  • 0

It seems that boost::multi_array<T, n> requires that T have a no-argument constructor. Consider the following example.

#include <boost/multi_array.hpp>

class ConstructorHasArguments {
    ConstructorHasArguments(int arg) {};
}

int main() {
    boost::multi_array<ConstructorHasArguments, 1> foo;
    return 0;
}

This results in a compile error.

no matching function for call to ‘ConstructorHasArguments::ConstructorHasArguments()

The problem is that, when the copy constructor for boost::multi_array<T,n> tries to allocate space for the copy, it attempts to call T(). I could, of course, add a no-argument constructor to my class. But what if I have a class for which a no-argument constructor doesn’t make sense?

Is there a simple way to use boost::multi_array when T does not have a no-argument constructor?

  • 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-06-14T16:21:25+00:00Added an answer on June 14, 2026 at 4:21 pm

    It is not only the copy constructor – actually all constructors of boost::multiarray will call allocate_space(), which in turns invokes std::uninitialize_fill_n(base, allocated_elements_, T());. Therefore a constructor without argument is required here. I don’t think there is a way to bypass it if you still want to use boost::multi_array. (I am referring to the source code of boost-1.46.0.)

    An alternative may be like this: you allocate and initialize space by yourself. Then pass the address to boost::multi_array_ref. In this case you will have to manage the memory.

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

Sidebar

Related Questions

I have a Win32 application that uses boost::asio and openssl library but it seems
It seems that there is a implementation of rope in my /usr/include/c++/4.5.1/ext/rope (and ropeimpl.h
It seems that cmath for visual studio 2005 does not have erf(x). I am
I have a few projects that use boost::shared_ptr or std::shared_ptr extensively (I can convert
The code below crashes when uncommented and it seems that shared_array<> argument in get()
I have a class implemented in a .cpp file as follow : #include <ctime>
I have a privately scoped Boost.BiMap in a class, and I would like to
Seems that This will be an easy question for you but this problem is
Seems that even after unchecking the option in the PyDev/Debug preferenecs pane to launch
It seems that we can show layers and even use a different zPosition for

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.