i'm pretty new to C++ and am trying to make an array in which every element is of a specific bit-size. I've tried doing this:
Sequence<uint64_t>;
In which Sequence would be the array name and every element would have a size of 64 bits. However get the following error: "error: ‘Sequence’ does not name a type"
Thanks in advance!
            Asked
            
        
        
            Active
            
        
            Viewed 319 times
        
    0
            
            
         
    
    
        Pol
        
- 1
- 
                    6What makes you think that defining an array of `uint64_t` works any different from defining any other array? If you don't know how to declare arrays at all, then please start learning the language from a [good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). This is not a tutorial site. – user17732522 May 18 '22 at 13:49
- 
                    3`uint64_t array_name[array_size];`? Sounds like you could use a [good C++ book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – NathanOliver May 18 '22 at 13:50
- 
                    2What's a `Sequence`? The error is telling you that there's no such thing... – ChrisMM May 18 '22 at 13:53
- 
                    1@ChrisMM "_In which Sequence would be the array name_". They seem to just not know how syntax for variable declarations works at all. – user17732522 May 18 '22 at 13:53
- 
                    1`vectorSequence;` should solve the issue – Marco Beninca May 18 '22 at 13:57
- 
                    @user17732522, you're right, missed that part. – ChrisMM May 18 '22 at 14:08
- 
                    In the code shown in the question, neither `Sequence` nor `uint64_t` is defined. So it's not the least bit surprising that it doesn't compile. – Pete Becker May 18 '22 at 14:34
1 Answers
5
            
            
        std::vector and std::array are the recomended array containers in C++.
You can use std::vector if you need a dynamic size array, e.g.:
#include <cstdint>
#include <vector>
std::vector<uint64_t> v;
And use std::array for a fixed size array, e.g.:
#include <cstdint>
#include <array>
std::array<uint64_t, 10> a;
You can see in the links above how to use these containers.
 
    
    
        wohlstad
        
- 12,661
- 10
- 26
- 39
- 
                    1
- 
                    @GoswinvonBrederlow thanks. MSVC didn't complain so I forgot it. Added now. – wohlstad May 18 '22 at 16:10