Go Down

Topic: Error: 'there.GPS::place' does not have class type (Read 652 times) previous topic - next topic

Hi All, I think I've ready every post I can find related to this but can't nail down the answer.  ;) Sorry for all the code. Can you help me out?

When I compile, the line
Code: [Select]
Serial.println(there.place.latitude()); in the main sketch causes the error:
[font=Courier New]In function 'void loop()':
error: 'there.GPS::place' does not have class type
[/font]
My main sketch
Code: [Select]

//SubSubClass.pde

#include "GPS.h"
#include "Location.h"

GPS      there = GPS(234, 567);

void setup()
{
 Serial.begin(115200);
 Serial.println("Program Start");
}

void loop()
{
 Serial.print("GPS Latitude:  ");

 //These two lines work
 Location temp = there.place();
 Serial.println(temp.latitude());
 
 //This line doesn't
 Serial.println(there.place.latitude());
 //In function 'void loop()':
 //error: 'there.GPS::place' does not have class type
 
 delay(1000);
}


GPS Class
Code: [Select]

//GPS.h

#ifndef GPS_h
#define GPS_h

#include "WProgram.h"
#include "Location.h"

class GPS
{
 public:
   GPS(int lat, int lon);
   Location place();
   
 private:
   Location _place;
};

#endif


Code: [Select]

//GPS.cpp

#include "GPS.h"

GPS::GPS(int lat, int lon): _place(lat, lon)
{
}

Location GPS::place()
{
 return _place;
}


Location Class
Code: [Select]

//Location.h

#ifndef Location_h
#define Location_h

#include "WProgram.h"

class Location
{
 public:
//    Location();
   Location(int latitude, int longitude);
   int latitude();
   int longitude();
   
 private:
   int _latitude;
   int _longitude;
};

#endif


Code: [Select]

//Location.cpp

#include "Location.h"

Location::Location(int latitude, int longitude)
{
 _latitude = latitude;
 _longitude = longitude;
}

int Location::latitude()
{
 return _latitude;
}

int Location::longitude()
{
 return _longitude;
}

There are 3 kinds of people in the world. Those who are good at maths, and those who aren't.

PaulS

Code: [Select]
Serial.println(there.place.latitude());
place is the name of a function. To invoke that function, you need () after it.

Giddy up! Two characters added, error dispelled!

Thank you PaulS. I'm very grateful for your expertise.

prawnhead
There are 3 kinds of people in the world. Those who are good at maths, and those who aren't.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy