Witam! Zacząłem niedawno przepisywać kod gry RPG którą napisałem pare lat temu. Więc zabrałem się za oddzielania struktur jak animacja, ruch itp. z głównego objektu gry. Problem pojewił się przy próbie dodania pozycji z klasy 'Position' do 'GameObject' gdzie dostaje komunikat , że 'p' czyli objekt klasy 'Position' nie jest typem. Powinienem użyć konstruktora klasy 'GameObject' do nadania wartości objektowi 'p' i tak zrobiłem. Klasa 'Position jest bardzo prosta i ma poprostu odzielić wszystkie funkcje i zmienne związane z pozycją od głównego objektu gry.
class GameObject;
class Position{
float x, y;
friend GameObject;
public:
Position(): x(0), y(0) {}
Position(float a, float b): x(a), y(b) {}
float GetX() { return x; }
float GetY() { return y; }
};
W sekcji protected w 'GameObject' deklaruje objekt powyższej klasy.
class GameObject{
[...]
protected:
Position p;
[...]
A potem próbuje go użyć w sekcji public.
public:
GameObject(): alive(true), collidable(0), p(0.0, 0.0), bound_x(0), bound_y(0),
max_frame(0), frame_x(0), frame_y(0), frame_count(0), frame_delay(0),
frame_width(0), frame_height(0), animation_columns(0), animation_row(0),
animation_direction(0), image(nullptr), alphac( al_map_rgb(255,0,255))
{}
virtual void Init( p.x, p.y, motion.vel.x, motion.vel.y,
int dir_x, int dir_y, int bound_x, int bound_y );
[...]
Komunikt Gcc:
||=== Build: Debug in EtlanKingdom (compiler: GNU GCC Compiler) ===|
/home/siery/Documents/Project/EtlanKingdom/precompiled/game_object.h|50|error: ‘p’ is not a type|
/home/siery/Documents/Project/EtlanKingdom/precompiled/game_object.h|50|error: expected ‘,’ or ‘...’ before ‘.’ token|
Dziękuję za pomoc!