Hi everyone,

I'm having issues incorporating something required by my assignment. I am supposed to create a class that has 2 private data members. One should be an array of 10 Database (Database being the name of the other class) objects. The other should be an integer that assigns the number of databases actually stored in the array.

This is what I tried:

#ifndef DATABASE_H
#define DATABASE_H
#include "database.h"

class DatabaseDB
{
     private:
             const int ARRAY_SIZE = 10;
             Database DatabaseArray[ARRAY_SIZE];
};

I am getting an error that reads "C++ forbids initialization of member ARRAY_SIZE" and "error making ARRAZY_SIZE static". How can I properly make these two private data members with no errors? Thank you.

This compiles for me.

class Database
{
   private:
     static const int num=10;
     int v[num];
};
int main(){
  Database db;
  return 0;
}

Just remember that the static means that is only one copy of this number for all classes.

Thanks, but unless I'm reading it wrong I don't see an array of objects in that code histrungalot. I need an array of Database objects to be defined privately in the class. Am I missing something?

int or object should be the same. Try putting the static in and see if it complies for you code

class foo
{
   private:
      int things; 
};
class Database
{
   private:
     static const int num=10;
     foo v[num];

};

int main(){
  Database db;
  return 0;
}

Works great, thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.