Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <array>
- template<typename T, size_t S> // Makes it so it's not specific to integers
- class Array
- {
- public:
- constexpr int Size() const { return S; } // Function's sole job is to return constant value of whatever S is set to
- private:
- T m_Data[S]; // Replaced int m_Data[S];
- };
- int main()
- {
- int size = 5;
- Array<int, 5> data; // Version of this class where T is set to int and size set to 5
- static_assert(data.Size() < 10, "Size is too large!"); // int Size() needs to be constexpr so it can be evaluated at compile time
- // If not, data from data.Size() will be an error since it must have a const value
- Array<std::string, data.Size()> newArray;
- for (int i = 0; i < data.Size(); i++)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement