Custom library problems

I'm trying to create a custom library to keep the order of inputs as they enter. However, I can't designate a size for the array that will store the values. Also, keywords doesn't work and every time I try to import it from Arduino IDE, it says that it already exists but it doesn't show up anywhere.
Any idea of how to fix it? Here is the ZIP file I created.
Thanks in advance.
Table.zip (3.7 KB)

Hi
Download the code from external resources is not in the tradition of the local community. Please do not force the users follow the links. Insert your code directly to the forum using code tags.

One way would be to make content a member variable and to use dynamic memory, e.g.,

class Table {
public:
  Table(size_t size) {
    content = new int[size];
  }
  ~Table() {
    delete[] content;
  }

  void add(int value);
  int show(int index);
  int fifo();
  int lifo();

private:
  int counter;
  int* content;
};

In the example, table1 can then be defined as follows.

Table table1(10);

Alternatively, a template could be used, e.g.,

template <size_t n>
class Table {
public:
  void add(int value);
  int show(int index);
  int fifo();
  int lifo();
  
private:
  int counter;
  int content[n];
};

template <size_t n>
void Table<n>::add(int value) {  // Move all methods to the header.
  // ...

Then table1 should be defined as follows.

Table<10> table1;

My bad, I'll take note for the next time, thanks

For some reason, when I type

Table table1 (10);

and compile, it returns this error:

no matching function for call to 'Table::Table(int)'

but in the cpp file, I've got this code:

#include <Arduino.h>
#include "Table.h"

void Table::Table(int size)
{
    int content [size] = {};
}

void Table::add(int value)
{
  content [counter] = value;
  counter++;
}

int Table::show(int index)
{
  return content [index];
}

int Table::fifo ()
{
  int out = 0;

  if (counter != 0)
  {
    out = content [0];
    counter--;
    for (int i = 0; i < counter; i++)
    {
      content [i] = content [i+1];
    }
  }

  return out;
}

int Table::lifo ()
{
  int out = 0;

  if (counter != 0)
  {
    out = content [counter-1];
    counter--;
  }

  return out;
}

Any idea of how can I fix it?

EDIT: btw, why keywords do not show?

Yes, I gave you two options in post #3.

This code violates the rule of three/five/zero.

You should never perform resource management in classes whose primary purpose is not resource management. Similarly, never use new/delete outside of low-level resource management code. It has no place in higher-level classes like this one.

In this case, the Table class should have a member content of type std::vector<int>, and then follow the rule of zero.

If you don't have access to std::vector, you can use a different dynamic array class, but this should not affect the design of the Table class. And that dynamic array implementation should follow the rule of five (your example doesn't, and it will corrupt the heap if you copy a table).

Not sure if it is related, but you left url out of library.properties, I could not see the examples until that was corrected.

I tried them but still not working

You don't have a declaration of such a constructor in your header file.

That would be the next step indeed.

I am not sure how low or high level this library is intended to be or whether OP has access to std::vector but you are probably right.

If you don't need the class to be copyable (yet), you can explicitly disable the copy constructor and assignment operator, this prevents accidental copies that cause double frees:

class DynArray() {
  // ...
  DynArray(const DynArray &) = delete;
  DynArray &operator=(const DynArray &) = delete;
};

I tested both approaches before sharing them with you.

I tried the first one and for some reason, doesn't work, it still returning the same error of not having Table::Table(int) declared

I'm not having any trouble with that particular error while running the code you originally posted. Have you closed and restarted the IDE after making the changes?

Yes, I do all changes before opening the IDE, but the error comes when I declare the object like this:

Table table1(10)

or any int. The idea is to have that int to define the size of the array that will store the data

Here you go.

Table_dynamic.zip (2.9 KB)
Table_template.zip (2.6 KB)

Thanks, I'll take a look later and I'll you know if I have any problem