0

I want to make a class that inherits from base array class, and just add some new functionality for the sake of learning.

Now when I try using this code


class checkInherit : public array  

Error is

C++ argument list for class template is missing

Which I think is that I have to add some arguments. When I Peeked into Array built in array code, this is the code

// TUPLE INTERFACE TO array
template <class _Ty, size_t _Size>
class array;

template <class _Ty, size_t _Size>
struct tuple_size<array<_Ty, _Size>>
    : integral_constant<size_t, _Size> { // struct to determine number of elements in array

Now is there any way I can do this?

EDIT: My assignment at University is to make circular queue using built in arrays. Now What my thought is that If I somehow inherits from std::array and add some extra functions in it to make it act as circular queue. It might not be possible but at least I want to inherit std::array so that I can give it a try.

7
  • 2
    You shouldn't inherit from types that do not have a virtual destructor. What is the extra functionality you're trying to add? Commented Jun 16, 2020 at 12:21
  • I am given the assignment of the circular queue with array in my university. I thought why not inherit from the built-in an array and add the functionality which makes it circular queue. Commented Jun 16, 2020 at 12:23
  • 1
    @AhmadAnis - I'd suggest your problem is better solved with composition instead of inheritance. If you want to use inheritance though, you need to provide the template arguments (e.g., class checkInherit : public std::array<int, 17>). Commented Jun 16, 2020 at 12:26
  • @StephenNewell, It is giving error of TUPLE INTERFACE TO array at std::array and incomplete type is not allowed1 at <int,17> Commented Jun 16, 2020 at 12:29
  • 1
    @AhmadAnis -- What you are probably looking for is a container adapter. Look at std::stack for example. By default, a std::deque is used as the container, but can be changed using a template argument. Commented Jun 16, 2020 at 12:29

1 Answer 1

1

If your array is the standard std::array template, I won't recommend inheriting from it.

I want to make a class that inherits from base array class, and just add some new functionality for the sake of learning.

That smells like a very bad idea. Read a good C++ programming book then a C++ reference.

If you really want to do that, be sure to follow the C++ rule of five.

You might want to have a member in your class checkInherit which is some std::array, and redefine the appropriate member functions and operators.

This is just a guess.

Sign up to request clarification or add additional context in comments.

1 Comment

Yea, I guess this is not a good idea, and I will do it with member in my class which is std::array. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.