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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:06:25+00:00 2026-05-26T12:06:25+00:00

I’m new to programming and I’m trying to create an array of class objects,

  • 0

I’m new to programming and I’m trying to create an array of class objects, then initialize each component individually. I manage to declare my class array easily:

Classsystem.h

class RACE {

public:

    string name;
    string shortdescription;
    string description;
    int noobjects;
    bool objects[N];
    int agressiveness;
    bool hulls[nohulls];
    bool shields[noshields];
    bool weapons[noweapons];
    bool companies[nocompanies];
    double tax;
    double bank;
    double currency;
    int diplomacy[noraces];
    double population;

public:

    ~RACE(){}
    RACE() {
        name="Default Race";
        shortdescription="Default";
        description="Default";
        noobjects=0;
        for(int i=0; i<N;i++) { objects[i]=0; }
        agressiveness=0;
        for (int i=0; i<nohulls;i++) { hulls[i]=0 ; }
        for (int i=0; i<noshields;i++) { shields[i]=0; }
        for(int i=0; i<noweapons;i++) { weapons[i]=0; }
        for(int i=0; i<nocompanies;i++) { companies[i]=0; }
        tax=0;
        bank=0;
        currency=1;
    }

    RACE(string iname, int inoobjects, int iagressiveness, double itax, double ibank, double icurrency) {
        name=iname;
        noobjects=inoobjects;
        agressiveness=iagressiveness;
        tax=itax;
        bank=ibank;
        currency=icurrency;
        for(int i=0; i<N;i++) { objects[i]=0; } 
        for(int i=0; i<nohulls;i++) { hulls[i]=1; } 
        for(int i=0; i<noshields;i++) { shields[i]=1; }
        for(int i=0; i<noweapons;i++) { weapons[i]=1; } 
        for(int i=0; i<nocompanies;i++) { companies[i]=0; }
    }
};

races.h:

 races[0].name="anything";

main.ccp:

#include "stdafx.h"
#include "Classsystem.h"

RACE races[16];

#include "races.h"

int main(array<System::String ^> ^args)
{
return 0;
}

the errors reads:

races.h(1) : error C2466: cannot allocate an array of constant size 0
races.h(1) : error C2143: syntax error : missing ';' before '.'
races.h(1) : error C4430: missing type specifier – int assumed. Note: C++ does not support default-int
races.h(1) : error C2371: 'races' : redefinition; different basic types
control console.cpp(13) : see declaration of 'races'

this still produces the error.

  • 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-26T12:06:26+00:00Added an answer on May 26, 2026 at 12:06 pm

    After consulting with my crystal ball, I am going to go for a wild guess to explain the errors:

    1. error C2466: cannot allocate an array of constant size 0
    2. error C2143: syntax error : missing ';' before '.'
    3. error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    4. error C2371: 'races' : redefinition; different basic types
    \control console.cpp(13) : see declaration of 'races'
    

    And the guess is that:

    races[0].name = "anything";
    

    is at namespace level, outside of any function. The language does not allow you to add code at namespace level, and the compiler is getting confused. It is trying to match that against patterns for valid and is considering that races[0] is a declaration of an array of 0 elements (error 1) of implicit type int (C allowed the type specifier to be skipped in a declaration, and would default to int there –error 3). If that is a declaration, it must be followed by either ; or , but the compiler is reading a ., so it believes that to belong to the next expression, and that there should be a ; before it (error 2). Finally the whole declaration redefines the variable races to be an array of 0 int, while the first definition makes it an array of 16 RACE (error 4).

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.