classes and array of struct - syntax?

I am starting to use classes and have a question regarding array of struct declaration in a class file.

Here is my code thus far, which isn't much at this point, still working on correct syntax.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 #ifndef WordList_H
  #define WordList_H
  #include <iostream>
  #include <string>

  
  using namespace std;

  public:

  
  struct WordList {

  	string word;
	int times_t;
  };

  //member functions


  
  //constructors



  //sets



  //gets

  private:
  WordList WordRec[1000];

 };
  #endif 


I am not sure what goes where. I am assuming that the struct itself will be declared under public and that the array of the structs will be declared in private?
Last edited on
Your sort of there, WordList is proper syntax, but it isn't "inside" of anything.

Something more like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef WordList_H
#define WordList_H
#include <iostream>
#include <string>
  
using namespace std;
  
struct Word
{
// struct members are public by default

  string word;
  int times_t;
};

class WordList
{
// class members are private by default
  public:

  //public member functions  (set/get)
  //constructors
  //destructors

  private:

  //private member functions

  //private member variables
  Word WordRec[1000];

 };
  #endif  


The struct "Word" has to come before the class "WordList". However, there is no concrete order of the way things need to be inside of the class/struct. You could put private member variables first, public variables second, private functions third, and finally public functions (Or whatever you want, really).
Last edited on
Thank you - that helps a lot.
Topic archived. No new replies allowed.