Toon posts:

Probleem met class (C++)

Pagina: 1
Acties:

Verwijderd

Topicstarter
Hallo,

Ik probeer in een header-file een c++ klasse te declareren met deze code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef __CSHIP_H_
#define __CSHIP_H_

#include "include/Main.h" // includes voor oa. SDL_Surface

class CShip {
public:
    CShip();
    ~CShip();

    void Draw (SDL_Surface* surface);
    void MoveLeft();
    void MoveRight();

private:
    int         xpos;
    int         ypos;
    SDL_Surface *ship;
};

#endif

En ik krijg deze error (naast 24 andere, maar hier ligt de fout):
code:
1
error C2236: unexpected 'class' 'CShip'

Ik ben niet totaal n00b op het gebied van C++, maar het is erg lang geleden dat ik het gebruikt heb (alleen Java/C# de laatste tijd), dus ik weet niet precies waarom hij deze error geeft. Ziet er wel ok uit. Iemand enige idee?

Thx

  • whoami
  • Registratie: December 2000
  • Laatst online: 07-09 19:30
Wat als je die conditionals eens weglaat?

Heb je ook wel die functies verder uitgewerkt die je in uw class gedefinieert hebt? Of toch tenminste het 'skelet' geschreven?

https://fgheysels.github.io/


  • ^Mo^
  • Registratie: Januari 2001
  • Laatst online: 04-11-2025
De fout kan net zo goed veroorzaakt worden door die 24 anderen hoor... ik zou daar eerst maar naar kijken, ik zie de fout hier niet zo direct staan..

- Edit -
'k zie dat je er net een include bij hebt gezet, wat staat daar allemaal in?

"There are 10 kinds of people in the world, those who understand binary and those who don't" | Werkbak specs


Verwijderd

Topicstarter
Als ik die conditionals weglaat, nog steeds hetzelfde. Ik heb mijn class uitgewerkt in CShip.cpp, het zier er zo uit:
code:
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "include/Main.h"
#include "include/CShip.h"

//
// CShip constructor
//
CShip::CShip() {
    xpos = 290;
    ypos = 420;
    
    // load ship data
    ship = SDL_LoadBMP ("data/spaceship.bmp");
    
    // set alpha channel of loaded images
    SDL_SetColorKey (ship, SDL_SRCCOLORKEY, SDL_MapRGB(ship->format, 255, 0, 255));
}

//
// CShip destructor
//
CShip::~CShip() {
    ship = NULL;
}

//
// Draw ship on surface <surface>
//
void CShip::Draw (SDL_Surface* surface) {
    SDL_Rect dest;
    dest.x = xpos;
    dest.y = ypos;

    SDL_BlitSurface (ship, NULL, surface, &dest);
}

//
// Move ship left
//
void CShip::MoveLeft() {
    (xpos > 0) ? xpos -= 4 : xpos = 0;
}

//
// Move ship right
//
void CShip::MoveRight() {
    (xpos < SCREENW - ship->w) ? xpos += 4 : xpos = SCREENW - 60;
}

Verwijderd

Topicstarter
Op zaterdag 25 mei 2002 15:00 schreef _Mo_ het volgende:
De fout kan net zo goed veroorzaakt worden door die 24 anderen hoor... ik zou daar eerst maar naar kijken, ik zie de fout hier niet zo direct staan..
Klopt, maar dit is de eerste fout in het rijtje.. dus weet niet zo goed waar te beginnen :)

  • ^Mo^
  • Registratie: Januari 2001
  • Laatst online: 04-11-2025
Op zaterdag 25 mei 2002 15:01 schreef flowmaster het volgende:

[..]

Klopt, maar dit is de eerste fout in het rijtje.. dus weet niet zo goed waar te beginnen :)
Maar wat staat er in main.h? Als je daar iets bent vergeten (bijvoorbeeld ; na de class definitie) dan kun je dit soort fouten krijgen...
Je include Main.h in CShip.h maar ook in CShip.cpp, deze tweede keer is echter overbodig aangezien in de cpp file al CShip.h wordt ge-include (en dus Main.h)

"There are 10 kinds of people in the world, those who understand binary and those who don't" | Werkbak specs


Verwijderd

Topicstarter
Ik had idd die main.h erbij gezet, maar zelfs zonder die kreeg ik die error..

Main.h:
code:
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
30
#ifndef __MAIN_H_
#define __MAIN_H_

#include <stdio.h>
#include <stdlib.h>

#include <SDL/SDL.h>

#define SCREENW 640     // horizontal resolution
#define SCREENH 480     // vertical resolution

#define MAXSTARS 256    // maxmimum number of stars

//
// Structure for stars
//
struct TStar
{
    float x, y;             // position of the star
    unsigned char plane;    // remember which plane it belongs to
};

//
// Structure for rocket
//
struct TRocket {
    int x, y;
}

#endif

  • ^Mo^
  • Registratie: Januari 2001
  • Laatst online: 04-11-2025
Op zaterdag 25 mei 2002 15:05 schreef flowmaster het volgende:
Ik had idd die main.h erbij gezet, maar zelfs zonder die kreeg ik die error..

Main.h:
code:
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
30
#ifndef __MAIN_H_
#define __MAIN_H_

#include <stdio.h>
#include <stdlib.h>

#include <SDL/SDL.h>

#define SCREENW 640     // horizontal resolution
#define SCREENH 480     // vertical resolution

#define MAXSTARS 256    // maxmimum number of stars

//
// Structure for stars
//
struct TStar
{
    float x, y;             // position of the star
    unsigned char plane;    // remember which plane it belongs to
};

//
// Structure for rocket
//
struct TRocket {
    int x, y;
}

#endif
; na de laatste struct :)

"There are 10 kinds of people in the world, those who understand binary and those who don't" | Werkbak specs


Verwijderd

Topicstarter
|:( |:( |:(

:D :P

Bedankt mensen, ik zal maar niks zeggen over hoe dom dit wel niet is heh...

  • ^Mo^
  • Registratie: Januari 2001
  • Laatst online: 04-11-2025
Op zaterdag 25 mei 2002 15:07 schreef flowmaster het volgende:
|:( |:( |:(

:D :P

Bedankt mensen, ik zal maar niks zeggen over hoe dom dit wel niet is heh...
Tja, kan je lastig overheen kijken dit soort dingen :) Als je ooit nog eens zo'n error krijgt, kijk dan in elk van je includes of je misschien een ; bent vergeten

"There are 10 kinds of people in the world, those who understand binary and those who don't" | Werkbak specs

Pagina: 1