-3

我收到此错误

当试图为类玩家制作一个对象时......

main.cpp|24|error: 'pic' 没有命名类型

这是代码

这是我的播放器.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

1 回答 1

3

您不能在函数之外执行此操作:

pic->upperrow=0;

您可以声明(并初始化全局变量),但仅此而已。

于 2012-07-31T10:09:53.707 回答