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

  • SEARCH
  • Home
  • 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 6653579
In Process

The Archive Base Latest Questions

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

I want to create a class one of whose private: members is a struct

  • 0

I want to create a class one of whose private: members is a struct point(see below). The public members ndim and numparticles are
set at run-time by the user, which are used to create corresponding arrays inside the class . However I am getting a compiler error. I don’t understand where I messed up.

The compiler error being displayed:

nbdsearch.h:25: error: ‘point’ does not name a type
nbdsearch.h:24: error: invalid use of non-static data member ‘nbdsearch::ndim’
nbdsearch.h:31: error: from this location
nbdsearch.h:31: error: array bound is not an integer constant before ‘]’ token

The class code:

class nbdsearch{
 public: 
  int ndim,numparticles;
  point particlevec[numparticles];


 private: 
  struct point{
    string key;
    double cood[ndim];
              };

};
  • 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:17:15+00:00Added an answer on May 26, 2026 at 1:17 am

    nbdsearch.h:31: error: array bound is not an integer constant before ‘]’ token

    double cood[ndim];
    

    Array size needs to be a compile time constant and ndim clearly isn’t. ndim is a variable.

    error: ‘point’ does not name a type

    point particlevec[numparticles];
    

    On line 25, compiler doesn’t know what point is. The structure is defined at a later point. Compilers in C++ work on a top to bottom approach(Not sure whether C++0X relaxes this rule). So, what ever types being used should be known to it before hand.

    Try this –

    class nbdsearch{
     private: 
      struct point{
        string key;
        std::vector<double>cood;
      };
     public: 
        int ndim,numparticles;
        std::vector<point> particlevec;   
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a new object using Class::DBI. One of the fields of
I want to create a class with a nested enum. public class Foo {
I want to create whois class like that public class DomainInfo { public string
I want to create a dll from a class library in one solution, then
I want to create a class that initializes a timer which will be used
I want to create a Class, say MyDiv , which inherits from the original
NET MVC and i want to create a class to contain site wide functions
I have a question regarding dependency injection. say i want to create a class
I'm having a problem with curl_multi_* , I want to create a class /
I want to create a static class in PHP and have it behave like

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.