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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:11:32+00:00 2026-05-26T01:11:32+00:00

I’ve got a class, and part of the input into the class is a

  • 0

I’ve got a class, and part of the input into the class is a vector (called Data) of variable length (lets say it has length N). I’ve included this after the function:

    N = data_->size();

In the private section of the class, I want to declare an array double A[N][N];. However, when I try to do this, I get something saying

error: “N is not a type name, static, or enumerator”.

How do I create the array A[N][N]?

Sorry if this is already explained somewhere else, as I’m very new to c++, so wouldn’t even know what to look for!

Edit — attached code:

    class foo {     
    public:
        foo (std::vector &data)
    : data(data_)
    {
        N = data_->size();
        M =  /* four times the last member of data (which is a vector of positive integers)*/
    }

    private:
      double A[M][M];

    void foo(void)
    {
      for (std::size_t i=1; i<=M; ++i)
        {
          A[i][i] = 1;
        }
    }
    };

Hope that makes some sort of sense… How would I be able to define A[M][M]? Maybe it’s not possible to do it for M as M is a function of the data. If not possible for M, is it possible for N?

One possibility I can think of is that I can make A a std::vector< std::vector<double> > A and then push a lot of 0’s or something into it, and THEN modify the values…

  • 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-26T01:11:33+00:00Added an answer on May 26, 2026 at 1:11 am

    Hmmm…several issues here…

    • Neither N nor M are declared (either in the constructor or as members of foo)
    • You are trying to initialize a member data that is not declared (and you may mean data_(data) as the syntax is member(expression), not expression(member))
    • The argument to your constructor is an incomplete type: it needs to be std::vector< sometype >; if you want it to be generic you’ll need to use templates or get some help from boost
    • You are not initializing the only member variable that you have declared (A)
    • void foo(void) is a problem because it is not the correct syntax for a constructor (which has no type) but uses the class name

    Let’s build up to something closer to what you want

    Start with a class foo:

    class foo {
    };
    

    with a constructor taking a single argument of type std::vector<double>

    class foo {
    public:
      foo(std::vector<double> &data);
    };
    

    you want to initialize a member variable with the data

    class foo {
    private:
      std::vector<double> data_;
    public:
      foo(std::vector<double> &data)
        :data_(data)
      {};
    };
    

    At this point I’ll note that I would generally not put the definition of a non-trivial constructor in the class declaration, but in a implementation file instead, and consequently I would be able to put the declaration of member variable beneath the public section with the declaration of the constructor. But for compactness I’ll leave this way here.

    You want to capture and store the size of the data

    class foo {
    private:
      std::vector<double> data_;
      size_t N;
     public:
      foo(std::vector<double> &data)
        :data_(data)
        ,N(data.size())
      {};
    

    };

    At this point we still haven’t made that multi-dimensional storage that you want, but now you have some decisions to make about how to manage the storage. If you use Kerrek SB’s approach this looks something like

    class foo {
    private:
      std::vector<double> data_;
      size_t N;
      std::vector< std::vector<double> > A;
    public:
      foo(std::vector<double> &data)
        :data_(data)
        ,N(data.size())
        ,A()
      {
        A.resize(N);
        for (size_t i=0; i<N; ++i) {
          A[i].resize(N);
        }
      };
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

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.