classes and inheritence

Im stuck with using a class from a library in a selfmade class. I think i understood the fundemantals of using classes and inheritance but somehow im trying for two days now and still cant solve my problem. So help would be very much appreciated.

Here is the code:
Asteroid.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#ifndef _ASTEROID_HPP
#define	_ASTEROID_HPP
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>


class Asteroid : public sf::Shape {

private:
    float X;
    float Y;
    float Radius;
    const sf::Color& Col;
    float Outline;
    const sf::Color& OutlineCol;

public:

    Asteroid(float X, float Y, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0))
            : sf::Shape::Circle(X, Y, Radius, Col, Outline, OutlineCol)   {}

    Asteroid(const Asteroid& orig);
    virtual ~Asteroid();


};

#endif	// _ASTEROID_HPP 


Asteroid.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "Asteroid.hpp"
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics/Drawable.hpp>


Asteroid::Asteroid(float X, float Y, float Radius, const sf::Color& Col, float Outline, const sf::Color& OutlineCol)
{
   sf::Shape::Circle(X, Y, Radius, Col, Outline, OutlineCol);
}

Asteroid::Asteroid(const Asteroid& orig) {
    
}

Asteroid::~Asteroid() {
}


Here is what the compiler has to say:
In file included from main.cpp:9:
Asteroid.hpp:22: error: expected `,' or `...' before '&' token
Asteroid.hpp:23: error: ISO C++ forbids declaration of `Color' with no type
Asteroid.hpp: In constructor `Asteroid::Asteroid(float, float, float, int)':
Asteroid.hpp:23: error: expected class-name before '(' token
Asteroid.hpp:23: error: uninitialized reference member `Asteroid::Col'
Asteroid.hpp:23: error: uninitialized reference member `Asteroid::OutlineCol'
main.cpp: In function `int main(int, char**)':
main.cpp:131: error: no matching function for call to `Asteroid::Asteroid(float, float, float, sf::Color, float, sf::Color)'
Asteroid.hpp:25: note: candidates are: Asteroid::Asteroid(const Asteroid&)
Asteroid.hpp:23: note: Asteroid::Asteroid(float, float, float, int)
I take it by line 14 that Color is declared in the sf namespace? That being the case, you'll need to prefix
all uses of Color with sf:: (see line 20).

Also, I'm not sure you want your class to hold const references to Colors for Col and OutlineCol. Do you
not want it to hold copies?
On line 131 you are not passing by reference when invoking the function from main.cpp. Perhaps you forgot a *?
Also if you do not want to have to write sf:: in front of everything that is a part of that namespace, use the the command:using namespace sf
Why do you define the really long Asteroid constructor twice? (It is in your header and implementation file.)
Last edited on
Topic archived. No new replies allowed.