Size() on static arrays inside a class.

I've been trying to using the command .size() to get the size of the arrays instead of creating a variable which is the same size of the array. I'm manually putting in the values i want to use in the array so it wont make sense to define a variable for its size
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
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>


using namespace std;

class Test {
  
  static  double hit_rate[];
  
  static  int fifo_width[];
  static int fsize;
  static int psize;  
  } 
 public:
  Test();
  ~Test(){};      
  //some functions
};




#include "FrontFifo.h" 

#include "SecondFifo.h"

#include "call.h"



    ////declaring static variables
    double Test::hit_rate[]={.5,.2,.4};
    int Test::fifo_width[]={5,10,20};
    int Test::fsize=fifo_width.size();
    int Test::psize=hit_rate.size();
  

int main() {
 srand( time(NULL) );/////seed random number generator to time
 Test();  

}



the error is:
38 request for member `size' in `Test::fifo_width', which is of non-class type `int[1]'

and

39 request for member `size' in `Test::hit_rate', which is of non-class type `double[1]'
There is no such a function as size() for arrays in C/C++. And an array is not a class. Arrays have no member functions.
Last edited on
aww thank you. I was looking at this http://www.cplusplus.com/reference/stl/array/size/ which seems to be wrong now. I instead used something like int Test::psize=sizeof(hit_rate)/sizeof(double);
That is reference to a stl container type "array", accessed via:

1
2
3
4
5
6
7
8
#include <array>

int main()
{
    std::array myarray;
    cout << myarray.size() << endl;
    return 0;
}


I could see how that might be confusing :)
@rollie
It is confusing only because you did not specify template arguments. Shall be for example

std::array<int, 10> myarray;

Obviously not what I meant; I could see how the documentation might be misleading. You think you are reading documentation for arrays, when you are actually reading documentation for an array class.
thanks for the help, it is much clearer now.
Topic archived. No new replies allowed.