Nieuws:

Ubuntu-NL weer online!

Na een periode van technische problemen en een overbelaste server zijn we eindelijk weer bereikbaar.
Samen met Hobbynet, onze sponsor en hostingpartner, hebben we een oplossing gevonden zodat alles weer soepel draait.

Bedankt voor jullie geduld en begrip. We hopen nu weer verder te gaan waar we gebleven waren.

Het team van Ubuntu-NL

Welkom, Gast. Alsjeblieft inloggen of registreren.
Heb je de activerings-mail niet ontvangen?

Auteur Topic: [C++] Include errors  (gelezen 1267 keer)

Offline JV.com

  • Lid
[C++] Include errors
« Gepost op: 2010/06/22, 17:28:55 »
Hallo iedereen,

Ik heb in mijn applicatie een hele hoop foutmeldingen verholpen. Nu heb ik een paar fouttmeldingen waar ik even niks meer van begrijp. volgens mij zijn het #include foutmeldingen.

Dit is mijn Include structuur:
Ball.cpp & Ball.h
Ball.cpp:
#include <SDL/SDL.h>
#include "Ball.h"
#include <iostream>
Ball.h:
#include <SDL/SDL.h>

Bat.cpp & Bat.h
Bat.cpp
#include <SDL/SDL.h>
#include "Bat.h"
Bat.h:
#include <SDL/SDL.h>

Graphics.cpp & Graphics.h
Graphics.cpp:
#include "Graphics.h"
#include <SDL/SDL.h>
#include <iostream>
Graphics.h:
#include <SDL/SDL.h>
#include "Ball.h"
#include "Player.h"

main.cpp
#include "Pong.h"
#include <iostream>

Player.cpp & Player.h
Player.cpp:
#include <SDL/SDL.h>
#include <iostream>
#include "Player.h"
Player.h:
#include <SDL/SDL.h>
#include <iostream>
#include "Bat.h"

Pong.cpp & Pong.h
Pong.cpp:
#include <SDL/SDL.h>
#include <iostream>
#include "Bat.h"
Pong.h:
#include <SDL/SDL.h>
#include "Graphics.h"
#include "Player.h"

Er is sprake van een overerving: de class player krijgt alle eigenschappen en waardes van de class Bat.

Dit is de compile Error die ik krijg:

In file included from Player.h:3,
                 from Pong.h:3,
                 from main.cpp:1:
Bat.h:3: error: redefinition of ‘class Bat’
Bat.h:4: error: previous definition of ‘class Bat’
In file included from Pong.h:3,
                 from main.cpp:1:
Player.h:5: error: redefinition of ‘class Player’
Player.h:6: error: previous definition of ‘class Player’
In file included from Player.h:3,
                 from Pong.h:3,
                 from Pong.cpp:2:
Bat.h:3: error: redefinition of ‘class Bat’
Bat.h:4: error: previous definition of ‘class Bat’
In file included from Pong.h:3,
                 from Pong.cpp:2:
Player.h:5: error: redefinition of ‘class Player’
Player.h:6: error: previous definition of ‘class Player’


Alvast bedankt voor de hulp!

Grt,

JV.com

Re: [C++] Include errors
« Reactie #1 Gepost op: 2010/06/22, 18:35:27 »
Eh, klinkt alsof je include guards nodig hebt:
http://en.wikipedia.org/wiki/Include_guard
I use a Unix-based system, that means I'll get laid as often as I have to reboot.
LibSylph
SeySayux.net

Offline JV.com

  • Lid
Re: [C++] Include errors
« Reactie #2 Gepost op: 2010/06/22, 18:40:44 »
@SeySayux:

Thanks Again, weer iets nieuws =). ga me er maar eens in verdiepen hoe dat werk!

EDIT:

Je wordt weer bedankt want ik hoefde alleen de include cards aan te geven en alles werkte na het compilen als een zonnetje!

Thanks!
« Laatst bewerkt op: 2010/06/22, 18:51:58 door JV.com »