mám zatím jen začátek programu a už mi to nejde zkompilovat, projekt má zatím 2 soubory: main.cpp a clovek.h
zdrojový kód main.cpp vypadá takto:
#include <allegro.h>
#include "clovek.h"
void init();
void deinit();
Clovek *clovek = new Clovek();
void InitDoubleBuffering()
{
obrazovka = create_bitmap(1024, 768);
}
void VykresliBuffer()
{
blit(obrazovka, screen,0,0,0,0,1024,768);
}
int main() {
init();
InitDoubleBuffering();
clovek->init(obrazovka);
while (!key[KEY_ESC]) {
clovek->move();
}
deinit();
return 0;
}
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1)
};
install_timer();
install_keyboard();
install_mouse();
}
void deinit() {
clear_keybuf();
}}}}}}}}}}}}}};
a když to chci zkompilovat hlásí to tyto chyby:
main.cpp: In member function `void Clovek::move()':
main.cpp:9: error: expected primary-expression before "void"
main.cpp:9: error: expected `;' before "void"
main.cpp:14: error: expected primary-expression before "void"
main.cpp:14: error: expected `;' before "void"
main.cpp:19: error: expected primary-expression before "int"
main.cpp:19: error: expected `;' before "int"
main.cpp:36: error: expected primary-expression before "void"
main.cpp:36: error: expected `;' before "void"
main.cpp:54: error: expected primary-expression before "void"
main.cpp:54: error: expected `;' before "void"
make.exe: *** [main.o] Error 1
prosím nevíte někdo co s tím, předem díky...
Fórum › C / C++
Prosím o radu
To majkl : problem je v tom, ze alokujes triedu 'Clovek' dynamicky mimo tela nejakej funkcie. Bud to sprav staticky ako napisal Bald3rr alebo takto:
Clovek *ptr; // pointer moze byt mimo tela funkcie
void init() {
// initalizacia
ptr = new Clovek(); // operator 'new' sa neda pouzit mimo tela funkcie
}
všechno sem dal do main.cpp, který teď vypadá takto:
#include <allegro.h>
class Clovek{
private:
int x2;
int y2;
BITMAP *BMclovek;
public:
void setY2(int my){
y2 = my;
};
void setX2(int mx){
x2 = mx;
};
int getY(){
return mouse_y;
};
int getX(){
return mouse_x;
};
int getY2(){
return y2;
};
int getX2(){
return x2;
};
void init(){
BMclovek = load_bitmap("clovek.bmp", NULL);
setY2(700);
setX2(700);
};
void draw(){
masked_blit(BMclovek, screen,0,0,getX(),getY(),47,39);
};
void draw2(){
masked_blit(BMclovek, screen,0,0,getX2(),getY2(),47,39);
};
void hide(){
//rectfill(canvas, 512-23, getY(), 512+24, getY()+39, makecol(0,0,0));
};
void moveDown2(){
hide();
y2 += 6;
if (y2 > 750) y2 = 750;
draw2();
};
void moveUp2(){
hide();
y2 -= 6;
if (y2 < 10) y2 = 10;
draw2();
};
void moveLeft2(){
hide();
x2 -= 6;
if (x2 < 10) x2 = 10;
draw2();
};
void moveRight2(){
hide();
x2 += 6;
if (x2 > 1020) x2 = 1020;
draw2();
};
void move(){
if (mouse_b & 2){
if (mouse_x < x2 && mouse_y < y2){
while (mouse_x == x2 || mouse_y == y2){
moveRight2();
moveDown2();
};
if (mouse_x == x2){
while (mouse_y == y2){
moveDown2();
};
if (mouse_y == y2){
while (mouse_y == y2){
moveRight2();
};
if (mouse_x < x2 && mouse_y > y2){
while (mouse_x == x2 || mouse_y == y2){
moveRight2();
moveUp2();
};
if (mouse_x == x2){
while (mouse_y == y2){
moveUp2();
};
if (mouse_y == y2){
while (mouse_y == y2){
moveRight2();
};
if (mouse_x > x2 && mouse_y < y2){
while (mouse_x == x2 || mouse_y == y2){
moveLeft2();
moveDown2();
};
if (mouse_x == x2){
while (mouse_y == y2){
moveDown2();
};
if (mouse_y == y2){
while (mouse_y == y2){
moveLeft2();
};
if (mouse_x > x2 && mouse_y > y2){
while (mouse_x == x2 || mouse_y == y2){
moveLeft2();
moveUp2();
};
if (mouse_x == x2){
while (mouse_y == y2){
moveUp2();
};
if (mouse_y == y2){
while (mouse_y == y2){
moveLeft2();
};
if (mouse_x == x2 && mouse_y == y2){
draw();
};
};
};
void deinit();
Clovek *ptr;
ptr = new Clovek();
void InitDoubleBuffering()
{
obrazovka = create_bitmap(1024, 768);
};
void VykresliBuffer()
{
blit(obrazovka, screen,0,0,0,0,1024,768);
};
int main() {
init();
InitDoubleBuffering();
clovek->init(obrazovka);
while (!key[KEY_ESC]) {
clovek->move();
};
deinit();
return 0;
}
void init() {
int depth, res;
allegro_init();
depth = desktop_color_depth();
if (depth == 0) depth = 32;
set_color_depth(depth);
res = set_gfx_mode(GFX_AUTODETECT, 1024, 768, 0, 0);
if (res != 0) {
allegro_message(allegro_error);
exit(-1)
};
install_timer();
install_keyboard();
install_mouse();
/* add other initializations here */
};
void deinit() {
clear_keybuf();
/* add other deinitializations here */
}}}}}}}}}}}}}};
a pořád to hlásí tyto chyby:
main.cpp: In member function `void Clovek::move()':
main.cpp:163: error: expected primary-expression before "void"
main.cpp:163: error: expected `;' before "void"
main.cpp:168: error: expected primary-expression before "void"
main.cpp:168: error: expected `;' before "void"
main.cpp:173: error: expected primary-expression before "int"
main.cpp:173: error: expected `;' before "int"
main.cpp:190: error: expected primary-expression before "void"
main.cpp:190: error: expected `;' before "void"
main.cpp:208: error: expected primary-expression before "void"
main.cpp:208: error: expected `;' before "void"
make.exe: *** [main.o] Error 1
proboha z kolika tisic stranek si to spatlal dohromady...
kdyz mas za if ( ... ) {
tak je dobre dat taky } za blok ke kteremu se to vztahuje....
urcite nepomuze kdyz nasazis }}}}}}}}}}} na konci programu... jako bys lepil parovod izolepou
za KAZDYM PRIKAZEM MUSI BYT ; tj. i za exit(-1);
nemluve o asi desitce dalsich nesmyslu ktery sem musel zlikvidovat aby se to dalo zkompilovat
pro jistotu ani nezkousim funkcnost.. ale podle toho jak je na tom kod, budes rad kdyz se to aspon nezhrouti :D
tak se to zkusil zkompilovat a napsalo mi to:
139: error: new types may not be defined in a return type
139: error: two or more data types in declaration of `deinit'
In function `void deinit()':
192: error: new declaration `void deinit()'
139: error: ambiguates old declaration `Clovek deinit()'
jo a jeste sem tak zbezne testoval a chce to jeste END_OF_MAIN() za konec main ... jen ciste toto bez stredniku...
viz. http://www.loomsoft.net/resources/alltut/alltut_lesson2.htm
no tak už to skoro funguje, ale eště něco se kompilátoru nelíbí:
[Linker error] undefined reference to `create_bitmap'
[Linker error] undefined reference to `_imp__screen'
[Linker error] undefined reference to `blit'
[Linker error] undefined reference to `_imp__key'
[Linker error] undefined reference to `_WinMain'
[Linker error] undefined reference to `_install_allegro_version_check'
[Linker error] undefined reference to `set_color_depth'
a asi ještě 50 dalších věcí.....
to uz zalezi na tom co pouzivas... dev-cpp:
2) Make sure that you've got the Allegro headers and libraries added into the project correctly from the Project | Options | Parameters Tab. (ALT-P, select Parameters at the top.) It should be added in the Linker section (Add Libraries or Objects).
z: http://qa.techinterviews.com/q/20060815072317AAEnY1K
tj to ALT-P - zalozka parametry a tam:
do kompilator a c++ compilator: -DALLEGRO_STATICLINK
do linker: -lalleg_s -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound
to je teda aspon vytazene z ukazkoveho prikladu z balicku allegro
Ach jo ,někteří lidé jsou zkrátka nepoučitelní
Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Uživatelé prohlížející si toto vlákno
Podobná vlákna
Prosím o radu! :) — založil brunoczech
Prosím o radu !!! — založil ospalka123
Prosím o radu — založil orei
Prosím o radu — založil Michal
Prosím o radu — založil dave3++
Moderátoři diskuze