Go Down

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

prawnhead

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;
}


PaulS

Code: [Select]
Serial.println(there.place.latitude());
place is the name of a function. To invoke that function, you need () after it.
The art of getting good answers lies in asking good questions.

prawnhead

Giddy up! Two characters added, error dispelled!

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

prawnhead

Go Up