Library error

Hi!
When I try to use my library that I've made, I get this error message: "sketch_aug31a.cpp: In function 'void loop()':
sketch_aug31a:12: error: request for member 'altitude' in 'foo', which is of non-class type 'Altitude ()()'" , and I cant really figure out what's causing this?
All help is appreciated!

#include "Arduino.h"
#include "Altitude.h"

float z;  // Height in meters
float T = 285; // Kelvin @ Air temp
float po = 101325;  // Pascal @ Sea level
float p = 45000;  // Pressure @ height
int R = 8.3144621; // Universal gas constant
int M = 28.97; // Moles @ Molemass of air
int g = 9.82; // m/s^2 @ Gravity
int pressureChange = 200; // Pascal


Altitude::Altitude()
{

}
void Altitude::altitude()
{
  if(p > 0)
  {
    z = (R*T/g*M)*log(po/p);  // Biometric altitude formula
    Serial.print(z);
    Serial.println(" meters above sea");
    delay(1000);
    p = pressureChange--;  // Decrease pressure over time (faking pressure sensor).
   }
   else
   {
     Serial.println("No Pressure");
     delay(1000);
   }
}
#include "Arduino.h"

#ifndef Altitude_h
#define Altitude_h

class Altitude
{
  public:
	void altitude();
  private:
	float z;
	float T;
	float po;
	float p;
	int R;
	int M;
	int g;
	int pressureChange;
};

#endif
#include <Altitude.h>

Altitude foo();

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  
  foo.altitude();
}

You haven't posted the function indicated by the error message.

void Altitude::altitude()

Names are case sensitive. The constructor name MUST be the same as the class name.

PaulS:

void Altitude::altitude()

Names are case sensitive. The constructor name MUST be the same as the class name.

Oh, that's not the constructor, its a method.
I have no constructor, cause I didn't thought it was necessary as I have no value to pass?
But if I have to, what should my constructor contain?

I've updated the first post now, as I added a constructor to the code, (empty).
However, I got a new error message: "sketch_aug31a.cpp: In function 'void loop()':
sketch_aug31a:12: error: request for member 'altitude' in 'foo', which is of non-class type 'Altitude ()()'"

It does no good to ask about errors in the sketch if you don't post the sketch. None of the errors shown have anything to do with the library per se.

PaulS:
It does no good to ask about errors in the sketch if you don't post the sketch. None of the errors shown have anything to do with the library per se.

I've updated the first post with all the code that I use, as I mentioned in my last post.

Altitude foo();

This is trying to call the foo() function, which, of course, you haven't defined. Loose the ().

Thanks! It worked now :slight_smile: