Home trying to create an array of classes(well default objects)
Reply: 2

trying to create an array of classes(well default objects)

elpmeplz
1#
elpmeplz Published in 2018-02-13 15:36:57Z

I have a class called Game and inside of game I want a board variable of the type Tool which I already made, I implemented the Tool class and had inserted default values in, when I try to create the array in the private section of Game I get a few errors;

syntax error: missing ';' before '*'

missing type specificier - int assumed.

unexpected token(s) precending ';'

My code so far:

class Game {
private:
Tool board[64]; <-- errors here
}
    class Tool {
      public:
          Tool(int n = -1, int x =-1 , int y = -1, bool side = false) {
             ......
          }
    }
Alan Birtles
2#
Alan Birtles Reply to 2018-02-13 15:39:11Z

You need semicolons on the end of each class declaration. Tool needs to be declared before it is used (i.e. above Game)

achal
3#
achal Reply to 2018-02-13 15:49:45Z

There are number of bugs in your code. class syntax looks like

class class_name {
    private: 
       data-member;
    public:
       member-function
};<-- you are missing this, should be closed using ;

Next thing, class Tool should be defined before class Game or do the forward declaration of class Tool first.

   class Tool {
      public:
          Tool(int n = -1, int x =-1 , int y = -1, bool side = false) {
             ......
          }
    };
    class Game {
       private:
       Tool board[64]; 
    };
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.300923 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO