2012-07-31 96 views
-3

努力,以便爲類玩家的對象時,我得到這個錯誤對象不命名類型的錯誤

.....

main.cpp|24|error: 'pic' does not name a type

這裏是代碼

這裏是我的player.h

#ifndef PLAYER_H_INCLUDED 
#define PLAYER_H_INCLUDED 

#include <allegro.h> 
#include <iostream> 

class player 
{ 

public: 
int upperraw; 
int middlerraw; 
int lowerraw; 
int firstcolumn; 
int seccolumn; 
int thirdcolumn; 
}; 

    #endif // PLAYER_H_INCLUDED 

我的main.cpp

#include "bitmap.h" 
#include "player.h" 
#include <allegro.h> 
#include <iostream> 

int onbitmap=1; 
bool turn=true; 

BITMAP *my_pic1; 
BITMAP *my_pic2; 
BITMAP *my_pic3; 
BITMAP *my_pic4; 
BITMAP *my_pic5; 
BITMAP *my_pic6; 
BITMAP *my_pic7; 
BITMAP *my_pic8; 
BITMAP *my_pic9; 

player *pic; 

pic->upperrow=0; 

player *one; 
player *two; 

static void nextturn() 
{ 
if(turn==1) 
{ 
    turn=0; 
} 
else 
{ 
    turn=1; 
} 
} 
static void drawsquares() 
{ 
my_pic1 = NULL; 
my_pic1 = load_bitmap("selected.bmp", NULL); 
my_pic2 = NULL; 
my_pic2 = load_bitmap("unselected.bmp", NULL); 
my_pic3 = NULL; 
my_pic3 = load_bitmap("unselected.bmp", NULL); 
my_pic4 = NULL; 
my_pic4 = load_bitmap("unselected.bmp", NULL); 
my_pic5 = NULL; 
my_pic5 = load_bitmap("unselected.bmp", NULL); 
my_pic6 = NULL; 
my_pic6 = load_bitmap("unselected.bmp", NULL); 
my_pic7 = NULL; 
my_pic7 = load_bitmap("unselected.bmp", NULL); 
my_pic8 = NULL; 
my_pic8 = load_bitmap("unselected.bmp", NULL); 
    my_pic9 = NULL; 
my_pic9 = load_bitmap("unselected.bmp", NULL); 

draw_sprite(screen, my_pic1, 218,146+65*1); 
draw_sprite(screen, my_pic2, 218,146+65*2); 
draw_sprite(screen, my_pic3, 218,146+65*3); 
draw_sprite(screen, my_pic4, 218+65,146+65*1); 
draw_sprite(screen, my_pic5, 218+65,146+65*2); 
draw_sprite(screen, my_pic6, 218+65,146+65*3); 
draw_sprite(screen, my_pic4, 218+65,146+65*1); 
draw_sprite(screen, my_pic5, 218+65,146+65*2); 
draw_sprite(screen, my_pic6, 218+65,146+65*3); 
draw_sprite(screen, my_pic7, 218+(65*2),146+65*1); 
draw_sprite(screen, my_pic8, 218+(65*2),146+65*2); 
draw_sprite(screen, my_pic9, 218+(65*2),146+65*3); 
} 

    static void replacebitmap(BITMAP *one,BITMAP *two) 
{ 
} 

static void readakey() 
{ 
int val=readkey(); 
switch (val >> 8) 
{ 

case KEY_LEFT: 
{ 


    switch (onbitmap) 
{ 

    case 1: 
    break; 
    case 2: 
    break; 
    case 3: 
    break; 
    case 4: 
    onbitmap=1; 


     my_pic4 = load_bitmap("unselected.bmp", NULL); 
    draw_sprite(screen, my_pic4, 218,146+65*1); 


    my_pic1 = load_bitmap("selected.bmp", NULL); 
    draw_sprite(screen, my_pic1, 218,146+65*1); 
    clear_keybuf(); 
    readakey(); 
    case 5: 
    onbitmap=5; 

    my_pic5 = load_bitmap("unselected.bmp", NULL); 
    draw_sprite(screen, my_pic1, 218,146+65*1); 

    my_pic2 = load_bitmap("selected.bmp", NULL); 
    draw_sprite(screen, my_pic1, 218,146+65*1); 
    clear_keybuf(); 
    readakey(); 

    case 6: 

     onbitmap=6; 

    my_pic5 = load_bitmap("unselected.bmp", NULL); 
    draw_sprite(screen, my_pic1, 218,146+65*1); 

    my_pic2 = load_bitmap("selected.bmp", NULL); 
    draw_sprite(screen, my_pic1, 218,146+65*1); 
    clear_keybuf(); 
    readakey(); 

    case 7: 

     onbitmap=7; 

    my_pic7 = load_bitmap("unselected.bmp", NULL); 
    draw_sprite(screen, my_pic7, 218,146+65*1); 

    my_pic4 = load_bitmap("selected.bmp", NULL); 
    draw_sprite(screen, my_pic4, 218,146+65*1); 
    clear_keybuf(); 
    readakey(); 

      case 8: 

     onbitmap=8; 

    my_pic8 = load_bitmap("unselected.bmp", NULL); 
    draw_sprite(screen, my_pic8, 218,146+65*1); 

    my_pic5 = load_bitmap("selected.bmp", NULL); 
    draw_sprite(screen, my_pic5, 218,146+65*1); 
    clear_keybuf(); 
    readakey(); 
} 
} 
} 
} 

int main(int argc, char *argv[]) 
{ 
allegro_init(); 
install_keyboard(); 
set_color_depth(32); 
set_gfx_mode(GFX_AUTODETECT, 640,480,0,0); 
BITMAP *my_pic = NULL; 
my_pic = load_bitmap("background.bmp", NULL); 
draw_sprite(screen, my_pic, 0,0); 

destroy_bitmap(my_pic); 
drawsquares(); 

readakey(); 
} 
END_OF_MAIN() 
+4

此代碼幾乎不可讀。 **發佈一個簡單的代碼**,說明問題,請!總的來說,這些代碼可以改進很多東西,但這是一個不同的主題。 – 2012-07-31 10:11:36

回答

3

你不能做到這一點的功能之外:

pic->upperrow=0; 

可以聲明(和intialize全局),但這是儘可能去。

+0

可以在函數外部執行它,只要將內存分配給pic指向的位置即可。因爲,上行是公開的。 – 2012-07-31 10:22:34

+0

@amalantony - 真的嗎?在c + +?這是我的新聞...(試試這個:http://ideone.com/5NwTg) – Nim 2012-07-31 11:57:57

+0

Nim,對不起。這是我的一個誤解。已投票刪除我的答案。 – 2012-07-31 16:06:37