braydenanderson2014 / C-Arduino-Libraries

This repository contains C++ and Arduino Libraries that are lightweight and easy to use. All libraries were created/mimicked by me and chatgpt.
Apache License 2.0
13 stars 0 forks source link

Error: 'Hashtable' was not declared in this scope Unable to use the lbrary #78

Closed virco closed 2 months ago

virco commented 3 months ago

Describe the Issue The library not working with the latest version of Arduino and ESP32

Library Name and Version: Name: Hashtable Version: 1.0.0

Environment:

Library Source:

Expected Behavior Compile the examples

Actual Behavior Examples report error during compilation: C:\Users\virco\AppData\Local\Temp.arduinoIDE-unsaved2024616-25348-1iian4e.3zv\Example\Example.ino: In function 'int main()': C:\Users\virco\AppData\Local\Temp.arduinoIDE-unsaved2024616-25348-1iian4e.3zv\Example\Example.ino:22:5: error: 'Hashtable' was not declared in this scope 22 | Hashtable<String, int> myHashtable; // Create a Hashtable with keys of type String and values of type int. You can declare Hashtable with any combination...<AnyType, AnyType> | ^~~~~ C:\Users\virco\AppData\Local\Temp.arduinoIDE-unsaved2024616-25348-1iian4e.3zv\Example\Example.ino:22:21: error: expected primary-expression before ',' token 22 | Hashtable<String, int> myHashtable; // Create a Hashtable with keys of type String and values of type int. You can declare Hashtable with any combination...<AnyType, AnyType> | ^ C:\Users\virco\AppData\Local\Temp.arduinoIDE-unsaved2024616-25348-1iian4e.3zv\Example\Example.ino:22:23: error: expected primary-expression before 'int' 22 | Hashtable<String, int> myHashtable; // Create a Hashtable with keys of type String and values of type int. You can declare Hashtable with any combination...<AnyType, AnyType> | ^~~ C:\Users\virco\AppData\Local\Temp.arduinoIDE-unsaved2024616-25348-1iian4e.3zv\Example\Example.ino:25:5: error: 'myHashtable' was not declared in this scope 25 | myHashtable.put("apple", 5); | ^~~ C:\Users\virco\AppData\Local\Temp.arduinoIDE-unsaved2024616-25348-1iian4e.3zv\Example\Example.ino:47:5: error: 'SimpleVector' was not declared in this scope 47 | SimpleVector keys = myHashtable.keys(); // Get a vector of all the keys in the hashtable | ^~~~ C:\Users\virco\AppData\Local\Temp.arduinoIDE-unsaved2024616-25348-1iian4e.3zv\Example\Example.ino:47:24: error: expected primary-expression before '>' token 47 | SimpleVector keys = myHashtable.keys(); // Get a vector of all the keys in the hashtable | ^ C:\Users\virco\AppData\Local\Temp.arduinoIDE-unsaved2024616-25348-1iian4e.3zv\Example\Example.ino:47:26: error: 'keys' was not declared in this scope 47 | SimpleVector keys = myHashtable.keys(); // Get a vector of all the keys in the hashtable | ^~~~

exit status 1

Compilation error: 'Hashtable' was not declared in this scope

To Reproduce Steps to reproduce the behavior:

  1. Include library '...'
  2. Initialize the library '...'
  3. See error

Error Message & Code Snippet If applicable, add the error message and the piece of code that causes the issue.


// Your code that triggers the error
Screenshots
If applicable, add screenshots to help explain your problem.

Additional Context
Add any other context about the problem here.

<!-- End of the issue report template. -->
virco commented 3 months ago

/* Example Name: Example For Hashtable Library

Basic example for the Hashtable library. This example demonstrates the basic functionality of the Hashtable library.

The circuit:
This Library does not Require any Circuits to run.

Created  month day year   // 02/18/2024
By author's name braydenanderson2014 (Brayden Anderson)
Modified day month year  // 02/18/2024
By author's name  braydenanderson2014 (Brayden Anderson)

https://github.com/braydenanderson2014/C-Arduino-Libraries/tree/Release/README.md

*/

include

include

int main() { Hashtable<String, int> myHashtable; // Create a Hashtable with keys of type String and values of type int. You can declare Hashtable with any combination...<AnyType, AnyType>

// Adding key-value pairs to the hashtable
myHashtable.put("apple", 5);
myHashtable.put("banana", 3);
myHashtable.put("cherry", 8);

// Retrieving values by key
int appleCount = myHashtable.getElement("apple");
int bananaCount = myHashtable.getElement("banana");

Serial.println("Apple count: " + appleCount);
Serial.println("Banana count: " + bananaCount);

// Removing a key-value pair
myHashtable.remove("cherry");

// Checking if a key exists
if (myHashtable.containsKey("cherry")) {
    Serial.println("Cherry exists in the hashtable.");
} else {
    Serial.println("Cherry does not exist in the hashtable.");
}

// Iterating through keys
SimpleVector<String> keys = myHashtable.keys(); // Get a vector of all the keys in the hashtable
for (const String& key : keys) { // Iterate through the keys, using a range-based for loop... String& is used to avoid copying the key
    Serial.print("Key: ");
    Serial.print(key.c_str()); // c_str() returns a pointer to the underlying char array of the String
    Serial.print(", Value: ");
    Serial.println(myHashtable.getElement(key)); // Get the value associated with the key
    Serial.println(*myHashtable.get(key)); // Get the value associated with the key using a pointer
}

return 0;

}

braydenanderson2014 commented 2 months ago

image

I apologize for not getting back to you sooner. I am aware of version 1.0 having issues with the arduino library manager. There should be version 1.0.1 that is a beta but it should have solved the issue. (Check the GitHub for it) https://github.com/braydenanderson2014/ArduinoHashtable

I tested myself and it was working just fine with no problems (1.0.0). Make sure you notice that the examples are in .cpp format and not .ino format which means that could cause problems.

braydenanderson2014 commented 2 months ago

I did notice when using the giga board arduino will not compile, so it's possible the issue occurs as well when you use an esp board. I would suggest using platformio as I have not encountered this problem with that at all with any board I have used. Unfortunately this appears to be an issue with arduino and not the library itself .