Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Dev-C++ "Build Error"

This thread is locked; no one can reply to it. rss feed Print
Dev-C++ "Build Error"
debylni
Member #14,054
February 2012

EDIT:Has been fixed.

So, I'm using Dev-C++ 4.9.9.2 (if it's important) and whenever I compile my code, I get this error: C:\DOCUME~1\MATU~1\PRACOV~1\C__~1\bjsource\Makefile.win [Build Error] ["../../../../../Documents and Settings/Matuš/Pracovná plocha/C++/bjsource/card.o"] Error 1

This is the "main.cpp" code:

#SelectExpand
1#include <allegro.h> 2#include <string> 3#include <vector> 4#include <time.h> 5#include <new> 6#include <sstream> 7#include "card.h" 8#include "button.h" 9#include "player.h" 10 11using namespace std; 12 13static void shuffle(vector<Card>); 14 15int main() { 16 //LOGIC INIT START 17 Player p,cpu; 18 vector<Card> deck; 19 int v; 20 stringstream ss; 21 for(int i=0;i<52;++i) { 22 if(i%13==0) v==11; 23 if(i%13>0 && i%13<9) v=i+1; 24 if(i%13>8) v=10; 25 ss << "cards\\" << i << ".png"; 26 deck.push_back(Card(v,ss.str())); 27 } 28 shuffle(deck); 29 //LOGIC INIT END 30 31 //BUTTON INIT START 32 Button drawBtn(638,370,124,60); 33 const char *drawBtnStd="btn\\drawStd.bmp"; 34 const char *drawBtnClick="btn\\drawClick.bmp"; 35 Button holdBtn(638,435,124,60); 36 const char *holdBtnStd="btn\\holdStd.bmp"; 37 const char *holdBtnClick="btn\\holdClick.bmp"; 38 //BUTTON INIT END 39 40 //ALLEGRO INIT START 41 allegro_init(); 42 install_keyboard(); 43 install_mouse(); 44 install_timer(); 45 set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,600,0,0); 46 set_window_title("BlackJack Stat v0.5 beta"); 47 show_os_cursor(1); 48 //ALLEGRO INIT END 49 50 //GRAPHICS START 51 rectfill(screen,0,0,600,600,makecol(11,129,16)); //play part (600x600) 52 rectfill(screen,600,0,800,600,makecol(0,0,0)); //info part (200x600) 53 rect(screen,605,5,795,595,makecol(255,255,255)); //info part trimming (5px margin) 54 textout_ex(screen,font,"CPU",10,10,makecol(255,255,255),makecol(11,129,16)); 55 textout_ex(screen,font,"Player",10,450,makecol(255,255,255),makecol(11,129,16)); 56 draw_sprite(screen,load_bitmap(drawBtnStd,0),drawBtn.x,drawBtn.y); //draw button 57 draw_sprite(screen,load_bitmap(holdBtnStd,0),holdBtn.x,holdBtn.y); //hold button 58 //GRAPHICS END 59 60 while(!key[KEY_ESC]) { 61 if(!drawBtn.isClicked() && !holdBtn.isClicked()) { 62 draw_sprite(screen,load_bitmap(drawBtnStd,0),drawBtn.x,drawBtn.y); 63 draw_sprite(screen,load_bitmap(holdBtnStd,0),holdBtn.x,holdBtn.y); 64 } 65 if(drawBtn.isClicked() && !holdBtn.isClicked()) { //draw click 66 draw_sprite(screen,load_bitmap(drawBtnClick,0),drawBtn.x,drawBtn.y); 67 } 68 if(holdBtn.isClicked() && !drawBtn.isClicked()) { //hold click 69 draw_sprite(screen,load_bitmap(holdBtnClick,0),holdBtn.x,holdBtn.y); 70 } 71 72 rest(50); 73 } 74 75 return 0; 76} 77END_OF_MAIN() 78 79static void shuffle(vector<Card> deck) { 80 int a,b; 81 srand(time(NULL)); 82 Card *temp; 83 for(int i=0;i<1024;++i) { 84 a=rand()%deck.size(); 85 b=rand()%deck.size(); 86 temp=new (nothrow) Card(deck[a].getVal(),deck[a].getImgPath()); 87 deck[a]=Card(deck[b].getVal(),deck[b].getImgPath()); 88 deck[b]=Card(temp->getVal(),temp->getImgPath()); 89 } 90 delete temp; 91}

This is the "card.h" code:

#SelectExpand
1#include <string> 2 3#ifndef CARD_H 4#define CARD_H 5 6class Card { 7 private: 8 int val; // <2;11> 9 bool ace; 10 std::string imgPath; 11 public: 12 Card(int,std::string); 13 int getVal(); 14 bool isAce(); 15 std::string getImgPath(); 16}; 17 18#endif

And this is the "card.cpp" code:

#include <string>
#include "card.h"

Card::Card(int v, std::string path) {
    val=v;
    imgPath=path;
    if(v==11) ace=true; else ace=false;         
}    
int Card::getVal() {return val;}   
bool Card::isAce() {return ace;}
std::string Card::getImgPath() {return imgPath;}

Anyone has an idea where the problem might be? I'd appreciate any useful answer.

Dizzy Egg
Member #10,824
March 2009
avatar

Has card.o been built and exists in the relevant folder? Also there is no deconstructor in your class...

----------------------------------------------------
Please check out my songs:
https://soundcloud.com/dont-rob-the-machina

debylni
Member #14,054
February 2012

Oh, thanks. The problem was that I haven't built all my classes (only main.cpp) and that caused error.
PS: I think that destructor isn't that that important, or is it?

Specter Phoenix
Member #1,425
July 2001
avatar

debylni said:

PS: I think that destructor isn't that that important, or is it?

General rule is that if you make your own constructor you need to make your own destructor.

"Can't a man even talk to himself without being interrupted?" -Krull(1983)
"Through vengence I was born. Through war I was trained. Through love I was found. Through death I was released. Through release I was given a purpose." -- Specter Phoenix
"Programming == AWESOME the rest is just tools to accomplish it."
END OF LINE

Oscar Giner
Member #2,207
April 2002
avatar

That's not really true. Most classes have a constructor, but they don't necessarily need a destructor.

The general rule is that if the class acquires resources (not necessarily at the constructor(s)), it'll need a destructor to release them (unless it's done somewhere else). This is not the case of the OP.

verthex
Member #11,340
September 2009
avatar

Using devcpp by the way is like using void main in your programming... way out of date.

Schyfis
Member #9,752
May 2008
avatar

It gets the job done and is pretty simple for the most part.
I do recommend Code::Blocks over it though.

________________________________________________________________________________________________________
[freedwill.us]
[unTied Games]

Specter Phoenix
Member #1,425
July 2001
avatar

That's not really true. Most classes have a constructor, but they don't necessarily need a destructor.

That is not what they drilled into us in my advanced programming course. Kept telling us that if you make a custom constructor then you need to make a custom destructor. Also was told to never use the default constructor, but to write one that at least initializes everything to a default value.

"Can't a man even talk to himself without being interrupted?" -Krull(1983)
"Through vengence I was born. Through war I was trained. Through love I was found. Through death I was released. Through release I was given a purpose." -- Specter Phoenix
"Programming == AWESOME the rest is just tools to accomplish it."
END OF LINE

kdevil
Member #1,075
March 2001
avatar

Your advanced programming course instructor probably decided it's safer to teach "always include a constructor/destructor" and then let people learn about the exceptions afterwards, rather than the other way around.

As Oscar said, you typically only need a destructor if your class acquires some sort of resource (allocating memory, opening a file, etc.) that needs to be released when the class is destroyed.

For example: If you have a class that contains a pointer, you'll want a constructor that allocates memory for that pointer and a destructor that frees the allocated memory. However, if you have a class that only contains variables like "int a; float b; bool c", it's still a good idea to create a constructor that initializes everything, but a destructor is unnecessary.

-----
"I am the Black Mage! I casts the spells that makes the peoples fall down!"

Specter Phoenix
Member #1,425
July 2001
avatar

Yeah, makes sense. I need to use constructors more in my code but I don't. I normally just let the defaults call and leave it at that.

"Can't a man even talk to himself without being interrupted?" -Krull(1983)
"Through vengence I was born. Through war I was trained. Through love I was found. Through death I was released. Through release I was given a purpose." -- Specter Phoenix
"Programming == AWESOME the rest is just tools to accomplish it."
END OF LINE

Go to: