1 Replies - 774 Views - Last Post: 15 September 2012 - 03:40 PM Rate Topic: -----

#1 oomjos  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 32
  • Joined: 09-September 12

Getting Error's I can't sove, Forward decleration amoung other

Posted 15 September 2012 - 12:51 PM

THE OUTPUT:
In file included from Moon.cpp:2:0:
Moon.h:6:1: error: expected class-name before ‘{’ token
Moon.h:14:11: error: return type specification for constructor invalid
Moon.h:15:21: error: ISO C++ forbids declaration of ‘setOrbitee’ with no type [-fpermissive]
Moon.cpp: In member function ‘Planet* Moon::getOrbiter()’:
Moon.cpp:22:21: error: invalid use of incomplete type ‘struct Planet’
Moon.h:4:7: error: forward declaration of ‘struct Planet’
Moon.cpp: At global scope:
Moon.cpp:25:9: error: expected unqualified-id before ‘double’
make: *** [Moon.o] Error 1

MAIN.CPP:
#include <iostream>
#include "Moon.h"
#include "Planet.h"
#include "Star.h"


using namespace std;

int main()
{
	
	Star* star = new Star(500.5, 1020);
	
	Planet* planet = new Planet(15.51, 120);
	planet->setOrbitee(star, 1000);
	if (planet->getOrbitee() == star)
		cout << "Pointer seems correct." << endl;
	else
		cout << "Make sure that the setters are correctly implemented." << endl;
	cout << "The gravity is: " << planet->calculateGravity() << endl;

	Moon moon(5.5, 10);
	moon.setOrbitee(planet, 250);
	if (moon.getOrbitee() == planet)
		cout << "Pointer seems correct." << endl;
	else
		cout << "Make sure that the setters are correctly implemented." << endl;
	cout << "The gravity is: " << moon.calculateGravity() << endl;		

	delete planet;
	delete star;
}



MOON.H
//Moon.h   
#ifndef MOON_H
#define MOON_H
class Planet;
class Moon : public CelestialBody
{
private:
double mass;
double diameter;

friend class Planet;
public:
Moon(double m, double d);
void Moon();
setOrbitee(Planet &x);
Planet* getOrbiter();

double calculateGravity(Planet *x);
};
#endif



Moon.CPP
//Moon.cpp
#include "Moon.h"
class Planet;
class Moon;
Planet *orbiteers;

int count =0;
Moon :: Moon(double m, double d)
{
  mass = m;
  diameter =d;
}

Moon :: Moon()
{
   mass = 0;
  diameter =0;
}

Planet* Moon:: getOrbiter()
{
  return (orbiteers+count);
}

Moon :: double calculateGravity(Planet *x){
double constantG = 0.00000006;

return (*this.getMass()/x.getMass())*constantG/2*(x.getDiameter + *this.getDiameter);
}



Is This A Good Question/Topic? 0
  • +

Replies To: Getting Error's I can't sove, Forward decleration amoung other

#2 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 617
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

Re: Getting Error's I can't sove, Forward decleration amoung other

Posted 15 September 2012 - 03:40 PM

Quote

Moon.h:6:1: error: expected class-name before ‘{’ token

You haven't forward declared CelestialBody which Moon is inheriting. That's probably the source of that error.

Quote

Moon.h:14:11: error: return type specification for constructor invalid

Constructors should not have a return type, that includes void. Remove any return type specifiers from your constructors declarations and definitions.

Quote

Moon.h:15:21: error: ISO C++ forbids declaration of ‘setOrbitee’ with no type [-fpermissive]

setOrbitee has no return type.

Quote

Moon.cpp: In member function ‘Planet* Moon::getOrbiter()’:
Moon.cpp:22:21: error: invalid use of incomplete type ‘struct Planet’

In Moon.cpp, Planet is an incomplete type (since it's only been forward declared). Before you make use of the type, you need to give the compiler the full definition (include the header file containing the definition of your Planet class).

Quote

Moon.cpp: At global scope:
Moon.cpp:25:9: error: expected unqualified-id before ‘double’

Your syntax is wrong for calculateGravity. Double check it.

This post has been edited by Aphex19: 15 September 2012 - 03:41 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1