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

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

user8607
1#
user8607 Published in September 21, 2018, 8:04 am

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) {
             ......
          }
    }
share|improve this question
  • 3
    Put class Tool before class Game. – john Feb 13 at 15:38
  • 3
    Swap the class definitions: an array needs its element type to be fully defined before use. – Quentin Feb 13 at 15:38
  • No, that's not your code so far. It's missing ; and is not even close to describing the whole issue. Create a Minimal, Complete, and Verifiable example. – StoryTeller Feb 13 at 15:38
  • I have the ; at the end of the classes already, and have swapped their places, still getting the errors though – elpmeplz Feb 13 at 15:41
  • It may sound ridiculous, but.. have you saved the source file before re-compiling? – Mateusz Grzejek Feb 13 at 15:42

2 Answers 2

active oldest votes
up vote 0 down vote
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO