Go Down

Topic: 'NewPing' does not name a type (Read 1 time) previous topic - next topic

BigNoob

Hello,

I'm trying to use the NewPing library ( http://playground.arduino.cc/Code/NewPing ) but get this error when trying to Verify my code:

Code: [Select]
In file included from newping_distance_sensor.cpp:7:
newping_distance_sensor.h:26: error: 'NewPing' does not name a type



just when I try to declare a variable:


Code: [Select]
    class DistanceSensor : public DistanceSensorDriver
    {
       
    private:
NewPing m_sensor;
    };


Countless people had this error because they didn't install the NewPing library but I have ! I can see it in Sketch > Import Library. AND I have the line

Code: [Select]
#include <NewPing.h>

at the top of my file (but the ".h" doesn't have the same color than "NewPing", is that normal?). I'm on Ubuntu 12.04

Any other idea?

PaulS

Quote
Any other idea?
The usual one for people that post in the Programming section without posting all of there code. But, I'll be nice and keep that to myself. Hopefully, though, you have an idea what you need to do.
The art of getting good answers lies in asking good questions.

michinyon

Did you restart the arduino IDE after you installed the library ?

michinyon

It seems to me,   there may be an issue that the NewPing class has no version of a constructor which takes zero arguments.

And your code might appear to require one.  Hard to say for sure without seeing all of your code.

But,  if that was so,   you should get a different error message to the one that you got.

BigNoob

The usual one for people that post in the Programming section without posting all of there code.
That would be a lot of code!

But I found a minimal not-working example and was able to find the problem.

This code works:

in main.ini:


Code: [Select]

#include "Robot.h"
#include <NewPing.h>
Robot robot;

void setup()
{
 
}

void loop()
{
 
}


in Robot.h:

Code: [Select]

#include <NewPing.h>

class Robot

  public:
    Robot() : sensor(1,2,3) {}
  private:
    NewPing sensor;
};


but it doesn't work if I comment out "#include <NewPing.h>" in main.ini, and I don't understand why since #include <NewPing.h> is still at the top of Robot.h !

UKHeliBob

Quote
it doesn't work if I comment out "#include <NewPing.h>" in main.ini, and I don't understand why since #include <NewPing.h> is still at the top of Robot.h !
I think you will find that this is a quirk of how the Arduino IDE assembles the actual file to be compiled from the bits an pieces needed, and that it a requirement to #include all library files used by the program in the master program file whether or not they are #included in library files.

By the way, do you really have a file called main.ini containing code or was that a typo ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

BigNoob

#6
Feb 04, 2015, 11:41 am Last Edit: Feb 04, 2015, 11:53 am by BigNoob
By the way, do you really have a file called main.ini containing code or was that a typo ?
Was a typo the file has another name.

OK good to know.

Edit: note this seems to be only with library files, my .h project files don't seem to have to be included in the master .ino file

Go Up