Pages: [1]   Go Down
Author Topic: Error: 'there.GPS::place' does not have class type  (Read 524 times)
0 Members and 1 Guest are viewing this topic.
Maitland, Australia
Offline Offline
Jr. Member
**
Karma: 1
Posts: 88
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

When I compile, the line
Code:
Serial.println(there.place.latitude());
in the main sketch causes the error:
In function 'void loop()':
error: 'there.GPS::place' does not have class type

My main sketch
Code:
//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:
//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:
//GPS.cpp

#include "GPS.h"

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

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

Location Class
Code:
//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:
//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;
}
Logged

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46113
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Maitland, Australia
Offline Offline
Jr. Member
**
Karma: 1
Posts: 88
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Giddy up! Two characters added, error dispelled!

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

prawnhead
Logged

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

Pages: [1]   Go Up
Jump to: