Mehrfachverebung
-
HI !
Ich habe zwei Klassen A und B.
A.h
#include <nötiges Zeug> class A { public: A(); void functionInA( Parameter ); }
A.cpp
#include "A.h" A::A() { //mach was } void A::functionInA( Parameter ) { //mach was }
B.h
#include <nötige Sachen> class B { public: B(); }
B.cpp
#include "B.h" B::B() { //mach was }
Okay C erweitert A und B
C.h
#include "A.h" #include "B.h" #include <other stuff> class C : public B , public A { public: C(); void functionInC(); }
C.cpp
#inlcude "C.h" C::C() : B() , A() { } void C::functionInC() { functionInA( Parameter ); }
Der Compiler behauptet jetzt die Funktin functionInA die ich in C.cpp aufrufe nicht zu kennen. Woran liegt das?
thx
Tom
-
Hallo,
bitte poste ein compilierbares Minimalbeispiel, das dein Problem demonstriert.
-
Gast9000 schrieb:
Der Compiler behauptet jetzt die Funktin functionInA die ich in C.cpp aufrufe nicht zu kennen. Woran liegt das?
Jeweils der selbe Funktionsname?
Dann versuch malC::C() : B() , A() { using A::function; }
-
Leider hat using A::function nicht funktioniert.
Okay hier mein Minimalbsp. Da mein Programm noch in den absoluten Anfängen ist und ich den Code ein bisschen abgespeckt habe, sollte das hier niemanden überfordern:
Painting.h#ifndef _PAINTING_H_ #define _PAINTING_H_ #include "SDL.h" #include <iostream> using namespace std; class Painting { public: SDL_Surface* display; void initalizeDisplay( int width , int height , int bpp ); void quit( char* message ); }; #endif
Painting.cpp
#include "Painting.h" #include <stdlib.h> #define MODE_FLAGS SDL_HWSURFACE | SDL_DOUBLEBUF void Painting::initalizeDisplay( int width , int height , int bpp ) { if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER ) == -1 ) quit("Painting Error: Could not initalize SDL."); display = SDL_SetVideoMode( width , height , bpp , MODE_FLAGS ); if( display == 0 ) quit("Painting Error: Could not setup video mode\n\0"); } void Painting::quit( char* message ) { cout << message << "\n"; SDL_Quit(); exit(-1); }
Input.h
#ifndef _INPUT_H_ #define _INPUT_H_ #include "SDL.h" using namespace std; class Input { public: SDL_Event* event; Input(); }; #endif
Input.cpp
#include "Input.h" Input::Input() { SDL_Event newEvent; event = &newEvent; // I prefer pointers }
Und Game.h das Painting und Input erbt:
#ifndef _GAME_H_ #define _GAME_H_ #include "Input.h" #include "Painting.h" class Game : public Input , public Painting { public: Game(); void startGame(); }; #endif
Game.cpp
#include "Game.h" Game::Game() : Input() , Painting() { } void startGame() { initalizeDisplay( 640 , 480 , 32 ); } int main( int argc , char** argv ) { }
Der Compiler meldet folgendes:
g++ -c `sdl-config --cflags` Game.cpp -o Game.o Game.cpp: In constructor `Game::Game()': Game.cpp:4: error: syntax error before `::' token Game.cpp: In function `void startGame()': Game.cpp:9: error: `initalizeDisplay' undeclared (first use this function) Game.cpp:9: error: (Each undeclared identifier is reported only once for each function it appears in.) make: *** [Game.o] Fehler 1
Hoffe mal das reicht.
Thx
Tom
-
Versuchs doch mal mit
void [b]Game::[/b]startGame() { initalizeDisplay( 640 , 480 , 32 ); }
ich glaub dat is besser
und pack die main-routine in ein extra file, sonst wird's unübersichtlich
mfg
Horst
-
Oh Mann erschieß mich !!!
Vielen Dank
Tom
-
edit: oh gott, bin ich langsam
-
nop
*Gast9000erschieß*
-
Gast9000 schrieb:
#include "Input.h" Input::Input() { SDL_Event newEvent; event = &newEvent; // I prefer pointers }
Du bist die ja hoffentlich bewusst, dass es newEvent nach Verlassen des Constructors nicht mehr gibt und event in die Pampa zeigt?