Dev-C++

Started by
25 comments, last by dustydoodoo 19 years ago
Quote:Original post by dustydoodoo
Well then whats wrong with the destructor!?

I dont know. What errors are you getting? Maybe you should post the entire class.
Advertisement
Never mind!, this stupid Dev_c++ is messed up!! im not using it anymore!
Sure i will write my signature, just gimme a piece of paper
Perhaps you should take a look at this tutorial. It is an Introduction to Classes and might be of some use for you to get an idea of the syntax of classes.
Quote:Original post by dustydoodoo
Never mind!, this stupid Dev_c++ is messed up!! im not using it anymore!


--ratings for blaming the IDE for your incompetence.

I think mike25025 is right, but we won't know for sure until you post your whole class.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
class Bitmap{              private:           bool BitmapLoaded;               public:           HBITMAP bitmap;           unsigned short int x;           unsigned short int y;                          ~Bitmap()           {                DeleteObject(bitmap);           }           void Load(LPSTR name)           {                 bitmap = LoadBitmap(name);           }              //DB stands for Display Bitmap           void DB(BUFFER *buffer, int x, int y)           {               DisplayBitmap(buffer, bitmap, x, y);           }                                  }; 


I got rid of the constructor, i didnt really need it... i guess.
Sure i will write my signature, just gimme a piece of paper
You don't really need the destructor either in this case either, because yours doesn't do anything that the default constructor won't do. If your class had pointers, that would be a different story.

However, you will need a constructor if you want to set defaults. Just make sure that the constructor is named after your class (i.e. void Bitmap()). Don't name it SetDefaults() because that will confuse your compiler.

Dev-C++ uses MinGW, which is an awesome compiler. Therefore if you find that your code doesn't work, it's probably not the compiler's fault.
Now that annoys me. Don't blame it on DevC++ for your stupid mistakes. DevC++ kicks ass. lol That function was not even a constructor because it didn't take the name of the class.
By the way, what did the error say, exactly? You don't necessarily have to define a constructor if all you want is for the member data to be initialized as NULL. The compiler should not have had any problem with you having a function called SetDefault() other than the fact that you didn't specify a type (i.e., void). What made the compiler think that SetDefault was supposed to be your constructor in the first place? It would be helpful if you posted the whole class definition plus the error message.
Dustydoodoo, here is one example of what you can do:
#include <windows.h>HINSTANCE g_hinstance;class Bitmap{              private:           bool BitmapLoaded;               public:           HBITMAP bitmap;           unsigned short int x;           unsigned short int y;           // Deconstructor           ~Bitmap()           {                if( BitmapLoaded )                    DeleteObject( bitmap );           }           // Constructor           Bitmap()           {               BitmapLoaded = false;           }            void Load(LPSTR name)           {                // In this function, you need two parameters, the first is the HINSTANCE of the program                // To get that you will need to save it from the:                // int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)                 bitmap = LoadBitmap( g_hinstance, name );                BitmapLoaded = true;           }              //DB stands for Display Bitmap I don't have this data so it's commented out           /*void DB( BUFFER *buffer, int x, int y)           {               DisplayBitmap(buffer, bitmap, x, y);           } */                                 }; int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {    // You will need to do this!    g_hinstance = hinstance;    return 0;}


Now that should work just fine, I tried it out myself. For a reference on the LoadBitmap function take a look here.

- Drew
now for some reason it says linker error for every win32 thing!!!
Sure i will write my signature, just gimme a piece of paper

This topic is closed to new replies.

Advertisement