Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

c++ - Object doesn't name a type error

I am getting this error

when trying to make an object for the the class player.....

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

here is the code

here is my 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

my 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()
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You cannot do this outside of a function:

pic->upperrow=0;

You can declare (and intialize globals) but that's as far as it goes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...